worker: fix crash when SharedArrayBuffer outlives creating thread#28788
worker: fix crash when SharedArrayBuffer outlives creating thread#28788addaleax wants to merge 1 commit intonodejs:masterfrom
Conversation
|
The two failures on other worker tests in CI might be related? |
|
@Trott I don’t know about |
|
Oh, yes, the I’ll figure out something for that. |
Use the parent thread’s `ArrayBuffer::Allocator` when creating a Worker instance, as that allocator is guaranteed to outlive the Worker itself. This requires making the zero-fill flag a thread_local variable in order to avoid race conditions between different threads. A test for that behaviour is added as well. Fixes: nodejs#28777 Fixes: nodejs#28773
446d7c5 to
14d4ad0
Compare
|
I’ve fixed that issue by now by using a thread_local but I’m not really happy with that as a solution … I’ll think about it a bit more. My ideal solution would be to turn the zero-fill field into an atomic counter and increasing/decreasing that from the threads, but I’m having a hard time thinking of a way to make it atomically accessible both from JS and C++. |
Good to land this in the meantime or you'd like to think on this bit some more? |
|
@Trott I strongly dislike this solution, and I’m still thinking about it … but haven’t been able to come up with somebody better so far. And hopefully, in the worst case we can get rid of it anyway when V8 removes ArrayBuffer::Allocator altogether in the future… |
|
AIX failure in CI is genuine? |
|
Hm … I’m assuming that it’s because of the |
|
Sorry it took me so long (the HTTP/2 security stuff got preference treatment here), but I came up with a solution that isn’t ideal either but definitely better than this and which should pass CI (→ #29190). I’ll close this PR as the code changes are completely different from the ones in this one. |
Keep a reference to the `ArrayBuffer::Allocator` alive for at least as long as a `SharedArrayBuffer` allocated by it lives. Refs: nodejs#28788 Fixes: nodejs#28777 Fixes: nodejs#28773
Use the parent thread’s
ArrayBuffer::Allocatorwhen creating aWorker instance, as that allocator is guaranteed to outlive the
Worker itself.
Fixes: #28777
Fixes: #28773
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes