json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Multiple DELETE requests crash server

Open lloydbanks opened this issue 5 years ago • 3 comments

db.json { "cart": [ { "id": 100, "count": 1 }, { "id": 101, "count": 1 } ] }

request

const url = 'http://localhost:3000/cart/'
const ids = [100, 101]
const deleteAll = ids.map(id => fetch(url + id, { method: 'DELETE' }))

Promise.all(deleteAll).then(result => console.log(result))

console

GET /cart 200 14.438 ms - 80
DELETE /cart/100 200 5.150 ms - 2
DELETE /cart/101 200 4.082 ms - 2
  ./src/api/db.json has changed, reloading...

  Loading ./src/api/db.json
  ./src/api/db.json has changed, reloading...
  Done

  Resources
  http://localhost:3000/cart

  Home
  http://localhost:3000

  ./src/api/db.json has changed, reloading...

  Loading ./src/api/db.json
  ./src/api/db.json has changed, reloading...
  Done

  Resources
  http://localhost:3000/cart

  Home
  http://localhost:3000

Cannot bind to the port 3000. Please specify another port number either through --port argument or through the json-server.json configuration file

Items are removed successfully but the server crashes. Not sure if something wrong with my code or it's a bug.

lloydbanks avatar Oct 12 '19 13:10 lloydbanks

I think it's a bug. I found that making more than 3 delete requests per second causes the server to crash.

orianmarx avatar Nov 20 '19 05:11 orianmarx

it happens with me also, did you solve it and how about custom endpoint delete all ?

HebaAhmadSaleh avatar Nov 15 '20 18:11 HebaAhmadSaleh

I also had this problem, and solved it by removing the watch flag when starting json-server. This way the server doesn't reload automatically and all the requests are successfully handled.

trindadeptr avatar Mar 08 '22 17:03 trindadeptr