-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets can emit close
before end
, breaking #479.
#490
Comments
@vqvu I was waiting for this fix. 'end' or 'error' isn't called when e.g. http requests to a server are aborted by the client... only 'close'... |
Yeah...I'm not sure what we can do about it, honestly. We can't support both the The best we can do here, is to add some sort of new I assume something like that would work for you? |
@vqvu: Yes, that would work... Right now I do this:
|
Can't we solve the socket case by testing whether more data can be retrieved after 'close' and if not 'end'. |
I'm not sure how. I don't know of any API that lets us check for buffered data. |
Not sure if this is any help? https://github.com/jshttp/on-finished |
That code does inspection on specific http request/response data structures, which we can't really do, since it doesn't apply to all Readables. However, it does give me an idea. See #505. We can simply punt the issue to the user entirely by allowing the second argument to be an arbitrary handler which can be as simple or complex as necessary. People can then delegate this behavior to a library like |
In this week's installment "Node Streams Incompatibility", it turns out that
Sockets
can emitend
afterclose
even though theReadable
streams docs say thatEmphasis mine.
#479 was written under the assumption that a
close
means no more data to emit. It will end the wrapper stream if it ever receivesclose
without having seenend
before. This seems compatible with theReadable
docs.However, for a
Socket
,close
means the client disconnected. There may still be buffered data previously received that has not yet been emitted. In fact, it is possible to receiveend
afterclose
(see below). The end result is that if you are slow at consuming the incoming data, and the client disconnects before you're done, the Highland stream will end,unpipe
from the socket, and you lose any pending data.Now, there's a reason why #479 tries to end the wrapper when it gets . It is possible to get
close
withoutend
(see below). If we don't close, the wrapper stream will never end.So now we have a case where we can't end on
close
or we lose data and a case where we must end onclose
or we hang. What should we do?I'm of the opinion that it is better to hand (visible though difficult to debug) than to throw away data (possibly not visible). Especially since the former case seems to require an explicit call to
destroy
by the user.Thoughts?
Close
beforeend
inSockets
I discovered this when messing around with sockets from the discussion in #489. Start this server.
In this example,
dest
starts out blocked, simulating slowness. In a different terminal, usetelnet
to send some data.Close the connection, you should see the server print out
Open a different connection and unblock the stream by sending the word
consume
.You will see this under v2.7.4
and this under
master
. Note all the missing data from the first client.Close
withoutend
Destroying an FS stream emits
close
but notend
.The text was updated successfully, but these errors were encountered: