Commit f50b9c1
worker: avoid potential deadlock on NearHeapLimit
It can happen that the `NearHeapLimit` callback is called while calling
the `oninit()` function on `MessagePort` construction causing a deadlock
when the `Worker::Exit()` method is called, as the `mutex_` was already
held on the `CreateEnvMessagePort()` method. To fix it, just use the
`mutex_` to protect the `child_port_data_` variable and avoid holding it
when creating the `MessagePort`.
Also, return early from `Worker::Run()` if the worker message port
could not be created.
Fixes: #38208
PR-URL: #38403
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>1 parent 70e094a commit f50b9c1Copy full SHA for f50b9c1
File tree
Expand file treeCollapse file tree
3 files changed
+37
-5
lines changedOpen diff view settings
Filter options
- src
- test/parallel
Expand file treeCollapse file tree
3 files changed
+37
-5
lines changedOpen diff view settings
Collapse file
+14-4Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
331 | 331 | |
332 | 332 | |
333 | 333 | |
334 | | - |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | + |
335 | 338 | |
336 | 339 | |
337 | 340 | |
| ||
383 | 386 | |
384 | 387 | |
385 | 388 | |
386 | | - |
| 389 | + |
387 | 390 | |
388 | | - |
| 391 | + |
| 392 | + |
| 393 | + |
| 394 | + |
| 395 | + |
| 396 | + |
389 | 397 | |
390 | 398 | |
391 | 399 | |
392 | | - |
| 400 | + |
393 | 401 | |
394 | 402 | |
395 | 403 | |
396 | 404 | |
| 405 | + |
| 406 | + |
397 | 407 | |
398 | 408 | |
399 | 409 | |
|
Collapse file
+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
70 | 70 | |
71 | 71 | |
72 | 72 | |
73 | | - |
| 73 | + |
74 | 74 | |
75 | 75 | |
76 | 76 | |
|
Collapse file
test/parallel/test-worker-nearheaplimit-deadlock.js
Copy file name to clipboard+22Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
0 commit comments