-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
crash in node_buffer.cc on ECONNRESET when using net.Socket onread #34346
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
net
Issues and PRs related to the net subsystem.
Comments
2 tasks
i think i managed to make a test script which will reliably crash under linux:
which gives
|
addaleax
pushed a commit
that referenced
this issue
Aug 8, 2020
CallJSOnreadMethod expects the return value to be undefined or a new buffer, so make sure to return nothing, even when an error causes us to destroy the stream. Fixes: #34346 PR-URL: #34375 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
codebytere
pushed a commit
that referenced
this issue
Aug 11, 2020
CallJSOnreadMethod expects the return value to be undefined or a new buffer, so make sure to return nothing, even when an error causes us to destroy the stream. Fixes: #34346 PR-URL: #34375 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
addaleax
pushed a commit
that referenced
this issue
Sep 22, 2020
CallJSOnreadMethod expects the return value to be undefined or a new buffer, so make sure to return nothing, even when an error causes us to destroy the stream. Fixes: #34346 PR-URL: #34375 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
addaleax
pushed a commit
that referenced
this issue
Sep 22, 2020
CallJSOnreadMethod expects the return value to be undefined or a new buffer, so make sure to return nothing, even when an error causes us to destroy the stream. Fixes: #34346 PR-URL: #34375 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
occasionally, we see nodejs 14.4.0 drop core with a message like:
it seems to be always the same location, and always in response to an ECONNRESET on the socket. it only happens when using the "onread" hook in net.Socket.
the good news: after some trial & error, and digging through the nodejs code, i think i figured out why:
when we set "onread", the Socket init sets
kBuffer
andkBufferCb
(net.js:306). theninitSocketHandle
will calluseUserBuffer
on the handle (net.js:254). this sets the uv listener to be aCustomBufferJSListener
(stream_base.cc:59). so far so good.when new data arrives,
OnStreamRead
callsCallJSOnreadMethod
(stream_base.cc:535). if the JS method returns a value, it's assumed to be a new buffer to use next time.the JS method is
onStreamRead
(stream_base_commons.js:163). if we got data, it returns nothing, unlesskBufferGen
is set, in which case it fetches a new buffer and returns that. cool.if we got a non-EOF error, it instead destroys the socket and returns (line 205). unfortunately it uses a shortcut and returns whatever value
destroy
returns.destroy
(destroy.js:5) always returnsthis
. so the Socket gets returned and treated as a new buffer until it fails the assertion inBuffer::Data
and crashes.i think the easiest fix for this is to replace net.js line 205 to not return the socket:
i tested this by monkey-patching the socket destroy function to return nothing:
this has been running for 6 days now without a crash, so i think it proves the fix.
The text was updated successfully, but these errors were encountered: