Uh oh!
There was an error while loading. Please reload this page.
_stream_wrap: prevent use after free in TLS - #1910
Conversation
indutny
commented
Jun 6, 2015
indutny
commented
Jun 6, 2015
cc @nodejs/crypto |
indutny
commented
Jun 9, 2015
@bnoordhuis : let's review it anyway, even without @EricTheOne's feedback the fix that it does is still relevant |
indutny
commented
Jun 9, 2015
cc @EricTheOne |
There was a problem hiding this comment.
Totally a noob question. Why are we not implementing this with an array instead of this complex enqueue and dequeue logic?
There was a problem hiding this comment.
Is queue supposed to be accessed directly from outside of the class?
Should it be prefixed or not?
There was a problem hiding this comment.
@thefourtheye because I'd like to avoid lookup cost when removing elements from it
@ChALkeR Should be prefixed, thanks.
There was a problem hiding this comment.
@indutny I am trying to understand this better. Theoretically, there will be no lookup in a queue, the first-in will be dequeued, right? If we are going to arbitrarily remove, then why not a Map?
There was a problem hiding this comment.
@thefourtheye there is no promise of FIFO here, and I like linked lists pretty much :)
indutny
commented
Jun 11, 2015
cc @trevnorris@shigeki@bnoordhuis@chrisdickinson maybe? Let's land this thing! |
EricTheOne
commented
Jun 11, 2015
@indutny this really seems to fix the original issue - no more segfaults and no more runaway memory allocations, thank you very much! I've been running my server for a while, and found a few errors which I haven't seen before: Maybe it's in my code, but I don't see it in the stack traces. The patch was applied over master (0f68377) |
There was a problem hiding this comment.
Can we const these, as we don't reassign anything to them?
trevnorris
commented
Jun 11, 2015
Patch looks good. I'd have to give it a closer look, but don't let that hold up merging it if more devs sign off before then. |
indutny
commented
Jun 16, 2015
Fixed the first problem, please take a look @EricTheOne |
EricTheOne
commented
Jun 17, 2015
@indutny thanks, the original onImmediate issue seemed to be due to my code (passed a function() instead of function in to setImmediate). Seems to be due to _handle being null in _stream_wrap.js: |
EricTheOne
commented
Jun 18, 2015
EricTheOne
commented
Jun 18, 2015
@indutny two more issues found, in addition to finishShutdown error: By far the most frequent is the finishShutdown error, second to it is EINVAL, and last is the assertion. |
EricTheOne
commented
Jun 22, 2015
@indutny is there any more info I can extract to help with the above three issues? |
indutny
commented
Jun 28, 2015
Fixed |
indutny
commented
Jun 29, 2015
@EricTheOne hopefully fixed the last ones two, thank you for reporting them! Please give it a try ;) |
EricTheOne
commented
Jun 29, 2015
@indutny this is excellent news! I applied the pull request over v2.3.1 and ran the server twice. The first thing to notice is that the server behaves much better:
We're very close to resolving this, however two issues still appear:
They happen at roughly the same time (less than 20 seconds apart) and then the server crashes. I use multiple processes so the errors may come from different child processes. I may have a clue - visually inspecting the logs, it seems that the two errors and a memory leak appear on reconnects. Especially I notice a lot of reconnects due to timeouts. I generally dispose of the sockets and create new ones. There is no kernel socket leak. |
indutny
commented
Jun 29, 2015
@EricTheOne may I ask you to provide a fresh stack trace for EINVAL? (Maybe both of read/write?) |
indutny
commented
Jun 29, 2015
@EricTheOne pushed one more fix, hope it helps |
EricTheOne
commented
Jun 30, 2015
@indutny with some more testing I found another issue (causing a crash). Not related to the latest commit (cb4a005): |
shigeki
commented
Jun 30, 2015
@EricTheOne Could you try the latest HEAD of master? I bleave it was fixed in #2064. |
EricTheOne
commented
Jun 30, 2015
@shigeki thanks, checking now, so far seems stable |
EricTheOne
commented
Jun 30, 2015
@shigeki@indutny#2064 indeed fixes the assertion, thanks. @indutny I have reduced the rate of reconnects on the server, and neither of the two errors happen even without cb4a005. It seems like cause was either a race condition or incorrect handling of edge cases. From my point of view this work solves the original issues and does not introduce new ones, hence I'd like to see it merged. |
indutny
commented
Jun 30, 2015
cc @trevnorris please do one more pass over it. @shigeki may I ask you to take a look too? |
Queued write requests should be invoked on handle close, otherwise the "consumer" might be already destroyed when the write callbacks of the "consumed" handle will be invoked. Fix: nodejs#1696
indutny
commented
Jun 30, 2015
There was a problem hiding this comment.
nit: throw in a comment on why the setImmediate() is necessary. future proofing for new devs. :)
There was a problem hiding this comment.
Actually, let's drop it out, and revert it back only in case of any troubles. I no longer think that it might be reasonable. (@EricTheOne: I hope you don't mind)
There was a problem hiding this comment.
@indutny I don't understand the code enough to comment on the code level, but I'll retest the final version and let you know if anything new comes up.
btw just to further my understanding, why would setImmediate be resolving possible troubles there?
trevnorris
commented
Jun 30, 2015
Left comments about cosmetic stuff, but LGTM. |
Queued write requests should be invoked on handle close, otherwise the "consumer" might be already destroyed when the write callbacks of the "consumed" handle will be invoked. Same applies to the shutdown requests. Make sure to "move" away socket from server to not break the `connections` counter in `net.js`. Otherwise it might not call `close` callback, or call it too early. Fix: #1696 PR-URL: #1910 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny
commented
Jul 1, 2015
Landed in 9180140, thank you! (Decided to squash everything into one commit, because I forgot what this hotfixes belonged too) |
EricTheOne
commented
Jul 1, 2015
@indutny thanks, I'll retest with master as soon as possible. |
Queued write requests should be invoked on handle close, otherwise the "consumer" might be already destroyed when the write callbacks of the "consumed" handle will be invoked. Same applies to the shutdown requests. Make sure to "move" away socket from server to not break the `connections` counter in `net.js`. Otherwise it might not call `close` callback, or call it too early. Fix: nodejs#1696 PR-URL: nodejs#1910 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Queued write requests should be invoked on handle close, otherwise the
"consumer" might be already destroyed when the write callbacks of the
"consumed" handle will be invoked.
Fix: #1696
cc @EricTheOne