You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
I've been spending lots of time tracking this down for multer, and form-data/multipart file uploader for express. Basically what we want to do is; whenever there is an error 1) unpipe the request 2) .resume() the request so that the browser will consider the request done.
This is implemented something like the code below. req is an http request from a browser.
It has been working great, most of the times. It seems like there is a problem when the stream contains too much data. For some reason it just doesn't emit any more data events, and the browser is stuck on uploading (xx%).
I've managed to track this down and have a small test-case that is easily replicated. The problem goes all the way down to net.Socket.
Calling req.resume after socket.pipe(out2) doesn't help.
If the size of each buffer (560000) is lowered it starts working. The break point on my machine is at 16 KiB, a.k.a 1024 * 16 doesn't work, but 1024 * 16 - 1 works.
The test case
varnet=require('net')varstream=require('stream')varport=5433varapp=net.createServer()functionlogStream(name){varout=newstream.Writable()out._write=function(chunk,encoding,cb){console.log('[server]['+name+'] received chunk of data')this.emit('chunk-received')cb(null)}returnout}app.on('connection',function(socket){varout1=logStream('out 1')varout2=logStream('out 2')out1.once('chunk-received',functionredirect(){console.log('[server] redirecting to `out 2`')socket.unpipe(out1)socket.pipe(out2)})socket.pipe(out1)})app.listen(port,function(){varsocket=newnet.Socket({allowHalfOpen: true})socket.connect(port,function(){setInterval(function(){socket.write(newBuffer(560000))},100)})})
Actual output
[server][out 1] received chunk of data
[server] redirecting to `out 2`
Expected output
[server][out 1] received chunk of data
[server] redirecting to `out 2`
[server][out 2] received chunk of data
[server][out 2] received chunk of data
[server][out 2] received chunk of data
[server][out 2] received chunk of data
[server][out 2] received chunk of data
[server][out 2] received chunk of data
...
The text was updated successfully, but these errors were encountered:
I've added some longer tests in LinusU/node-stream-bug which shows that 1) the client request isn't closed 2) the problem exists with net, http and express
I've been spending lots of time tracking this down for multer, and form-data/multipart file uploader for express. Basically what we want to do is; whenever there is an error 1)
unpipe
the request 2).resume()
the request so that the browser will consider the request done.This is implemented something like the code below.
req
is an http request from a browser.It has been working great, most of the times. It seems like there is a problem when the stream contains too much data. For some reason it just doesn't emit any more
data
events, and the browser is stuck onuploading (xx%)
.I've managed to track this down and have a small test-case that is easily replicated. The problem goes all the way down to
net.Socket
.Calling
req.resume
aftersocket.pipe(out2)
doesn't help.If the size of each buffer (
560000
) is lowered it starts working. The break point on my machine is at 16 KiB, a.k.a1024 * 16
doesn't work, but1024 * 16 - 1
works.The test case
Actual output
Expected output
The text was updated successfully, but these errors were encountered: