-
Notifications
You must be signed in to change notification settings - Fork 672
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
Fix thread-safety issues in native bindings replacing Nan::Persistent
with v8::Eternal
#1419
Fix thread-safety issues in native bindings replacing Nan::Persistent
with v8::Eternal
#1419
Conversation
I don't understand how using a |
Is the underlying reason for the worker-related issues that |
Thank you for the feedback! Yes, the underlying issue with worker threads is related to the use of a static While the primary distinction between I've also created rmnilin/ssh2-1393-repro to test both the current implementation and this fix. |
Hello, any update on this PR ? We can't restart dynamically a worker because of this bug. |
I guess @mscdex just doesn't have enough time. |
Thank you so much for fixing this <3 It crashed our servers |
just ran into this issue as well... really need to merge these changes in if |
5b68976
to
ec98b7e
Compare
@rmnilin Can you include a test in this PR? Other than that, I am fine with these changes I guess. |
ec98b7e
to
bcd8064
Compare
@mscdex Added the test 🤝 |
@rmnilin It looks like the new test will need to be skipped for older node versions. I think the best way to do that is to wrap the EDIT: There is also a lint error that needs to be fixed |
@mscdex I hadn't considered Node.js versions without the worker threads module. Thanks for pointing that out. I've also fixed the lint errors, and everything should be in order now. |
4274c26
to
243e193
Compare
Missed another one lint issue, fixed again... |
Thanks, landed in dd5510c. |
This PR addresses thread-safety issues in the native bindings of the library. It replaces
Nan::Persistent
withv8::Eternal
for constructor storage in cipher and decipher classes.The previous implementation using
Nan::Persistent
was not thread-safe, leading to crashes and undefined behavior when these classes were accessed from multiple threads simultaneously. This was particularly problematic when ssh2 was used in multi-threaded environments, such as when imported in worker threads.Key changes:
v8::Eternal
instead of aNan::Persistent
.Set
method of theEternal
handle.These changes ensure thread-safe storage of constructor handles without altering the intended functionality of the modules.
This PR addresses issue #1393 and resolves the reported crashes and segmentation faults related to multi-threaded use of the ssh2 library.