cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API. Parallel POST of Products. Unable to save Stock Item

Rest API. Parallel POST of Products. Unable to save Stock Item

Magento 2.2.5 CE.
I have implemented parallel requests to Magento to add Products. But in the case of more than 1 thread magento at the start (when all e.g. 5 requests come to Magento almost simultaneously during 0.01 s) sends back strange error "Unable to save Stock Item". Here is the http log:
-------------------------------------------------------------------
POST /index.php/rest/V1/products HTTP/1.1
Authorization: Bearer 6e1d4tpogjpxs5th03sxp6n0hdr3qs4e
Content-Length: 186
Content-Type: application/json; charset=UTF-8
Host: 192.168.99.100:54611
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_181)
Accept-Encoding: gzip,deflate

{"product":{"attribute_set_id":10,"name":"Cobalt CoolTech Fitness Short-32-Blue_Fri Aug 31 19:26:48 EEST 2018","price":44.0,"sku":"MSH01-32-Blue_Fri Aug 31 19:26:48 EEST 2018"}}HTTP/1.1 400 Bad Request
Date: Fri, 31 Aug 2018 16:26:50 GMT
Server: Apache/2.4.18 (Ubuntu)
Set-Cookie: PHPSESSID=o6d6tkbltrdhl1i3dc5tp11qvi; expires=Fri, 31-Aug-2018 17:26:50 GMT; Max-Age=3600; path=/; domain=192.168.99.100; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-UA-Compatible: IE=edge
Content-Length: 39
Connection: close
Content-Type: application/json; charset=utf-8

{"message":"Unable to save Stock Item"}

------------------------------------------------------
When I do it non parallel everything is ok.
--------------------------------------------------------

The picture of this process from WireShark:

I added pause between requests (100 ms) but now the same errors start appearing in the middle of process. So it does not make the situation more safe.

The question is: should Magento CE work in parallel or maybe it is not designed for this and I should make requests one by one?