In my frontend app I implemented mechanism which splits file into chunks and then sends their parts in a for loop like this (chunks is an array of strings - contents of file in binary form):
for (let i = 0; i < chunks.length; i++) {
sendFile(chunks[i], name, extension, mimeType, chunks.length, i);
}
It wasn't working though. I was getting this error:

So I thought - maybe I'll add a delay between each chunk emit and ye - it worked. If server is hosted on localhost, 20ms interval is enough:
for (let i = 0; i < chunks.length; i++) {
sendFile(chunks[i], name, extension, mimeType, chunks.length, i);
await sleep(20);
}
Now I deployed app to my VPS and error is back. I noticed that I had to increase sleep duration to 100ms for it to work.
What is causing this and how to address this issue?
Seems like long-polling transport method just sucks in general. Always aim to use websockets - it resolved my issue.