n-api: fix dead lock if multi push events#58724
Open
milkpotatoes wants to merge 1 commit intonodejs:mainfrom
Open
n-api: fix dead lock if multi push events#58724milkpotatoes wants to merge 1 commit intonodejs:mainfrom
milkpotatoes wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Member
|
@milkpotatoes would it be possible to add a test case? That would help use see the problem more easily as well as make sure its not regressed in the future. |
3547016 to
e2014e6
Compare
addaleax
reviewed
Jun 18, 2025
- add waiting_task_size to record waiting push events - compare max_queue_size before queue.size which would be faster Signed-off-by: milkpotatoes <chenshulin5@huawei.com>
e2014e6 to
6a94905
Compare
KevinEady
reviewed
Aug 22, 2025
| queue.pop(); | ||
| popped_value = true; | ||
| if (size == max_queue_size && max_queue_size > 0) { | ||
| if (max_queue_size > 0) { |
Contributor
There was a problem hiding this comment.
question: Why was size == max_queue_size removed? Can you clarify / elaborate?
Author
There was a problem hiding this comment.
This is a bug, due to thread awake could be slower than event loop thread gets the lock, tasks would be executing faster than send.
This will cause threads into sleeping unlimited.
max_queue_sizeis set (.e.g, 3).- queue is full.
- multi thread try to send task in one time, count of threads (.e.g, 3) is
max_queue_sizeor more. - threads will be waiting for signal in the time.
- task start to execute, pop the first data. At the time, queue size is 3, send a signal. The thread would not awake immediately. queue size--(by pop)
- unlock, and execute task, the task maybe executed faster than thread awake.
- execute next task, queue size will be 1.
- thread awake and push -> queue size: 2
- After that, other threads will never receive s signal until queue is full again or into release process.
code of node in current head (log added)
![]()
code of modules
![]()
run log
![]()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



fix #58723