typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.8k stars 7.02k forks source link

Multiple DELETE requests crash server #1037

Open lloydbanks opened 5 years ago

lloydbanks commented 5 years ago

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.

orianmarx commented 4 years ago

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

HebaAhmadSaleh commented 3 years ago

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

trindadeptr commented 2 years ago

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.