Skip to content

src: improve thread safety of TaskQueue - #57910

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
codebytere:mutex-flush-tasks
Apr 22, 2025
Merged

src: improve thread safety of TaskQueue#57910
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
codebytere:mutex-flush-tasks

Conversation

@codebytere

@codebyterecodebytere commented Apr 17, 2025

Copy link
Copy Markdown
Member

Closes#56236.

Improve thread safety of TaskQueue by making locking of TaskQueue explicit and thus hopefully preventing a crash due to uv_async_send being called with nullptr.

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Apr 17, 2025
@codecov

codecovBot commented Apr 17, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 97.56098% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.26%. Comparing base (5077ea4) to head (d71a542).
Report is 425 commits behind head on main.

Files with missing linesPatch %Lines
src/node_platform.cc97.53%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #57910 +/- ##
========================================
Coverage 90.25% 90.26% ========================================
Files 630 630 Lines 185691 186170 +479 Branches 36407 36480 +73 ========================================
+ Hits 167589 168039 +450 + Misses 10994 10975 -19 - Partials 7108 7156 +48 
Files with missing linesCoverage Δ
src/node_platform.h80.00% <100.00%> (+5.00%)⬆️
src/node_platform.cc88.70% <97.53%> (+0.83%)⬆️

... and 65 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment threadsrc/node_platform.h Outdated
Comment threadsrc/node_platform.h Outdated
Comment threadsrc/node_platform.cc Outdated
Comment threadsrc/node_platform.cc Outdated
@codebytere
codebytereforce-pushed the mutex-flush-tasks branch 2 times, most recently from 0ffd2a4 to f1b6765CompareApril 17, 2025 17:47
@mcollina

Copy link
Copy Markdown
Member

@codebytere I wonder if this could also help with #54918.

@codebyterecodebytere added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 18, 2025
@github-actionsgithub-actionsBot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Apr 18, 2025
@nodejsnodejs deleted a comment from github-actionsBotApr 18, 2025
@codebyterecodebytere removed the request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. label Apr 18, 2025

@bnoordhuisbnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some suggestions.

Comment threadsrc/node_platform.cc Outdated
Comment threadsrc/node_platform.cc Outdated
Comment threadsrc/node_platform.cc Outdated
@codebytere
codebytereforce-pushed the mutex-flush-tasks branch 2 times, most recently from 0192c4f to 78a514eCompareApril 19, 2025 10:42

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSLGTM

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 19, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 19, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@lpinca

lpinca commented Apr 19, 2025

Copy link
Copy Markdown
Member

@codebytere I wonder if this could also help with #54918

I applied this patch and unfortunately it does not.

@mcollina

Copy link
Copy Markdown
Member

Thanks for checking!

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@joyeecheungjoyeecheung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (as in, my tiny head can't find potential issues out of the new locks), though I think it can use a bit more comments (I am fairly certain that the race can only happen at shutdown, the platform is initialized too early for any tasks to be posted during that process)

Comment threadsrc/node_platform.cc Outdated
aduh95 pushed a commit that referenced this pull request May 16, 2025
PR-URL: #57910
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
aduh95 pushed a commit that referenced this pull request May 17, 2025
PR-URL: #57910
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
aduh95 pushed a commit that referenced this pull request May 18, 2025
PR-URL: #57910
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
aduh95 pushed a commit that referenced this pull request May 19, 2025
PR-URL: #57910
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
codebytere added a commit to electron/electron that referenced this pull request May 23, 2025
codebytere added a commit to electron/electron that referenced this pull request May 26, 2025
codebytere added a commit to electron/electron that referenced this pull request May 29, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 2, 2025
jkleinsc pushed a commit to electron/electron that referenced this pull request Jun 2, 2025
* chore: bump node in DEPS to v22.16.0
* crypto: remove BoringSSL dh-primes addition
nodejs/node#57023
* tools: enable linter in test/fixtures/test\-runner/output
nodejs/node#57698
* src: improve thread safety of TaskQueue
nodejs/node#57910
* buffer: define global v8::CFunction objects as const
nodejs/node#57676
* src: disable abseil deadlock detection
nodejs/node#57582
* zlib: fix pointer alignment
nodejs/node#57727
* chore: fixup patch indices
* src: set default config as node.config.json
nodejs/node#57171
* src: update std::vector<v8::Local<T>> to use v8::LocalVector<T>
nodejs/node#57578
* test: disable chmod tests failing in Docker
nodejs/node#58326
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 3, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 4, 2025
* chore: bump node in DEPS to v22.16.0
* crypto: remove BoringSSL dh-primes addition
nodejs/node#57023
* tools: enable linter in test/fixtures/test\-runner/output
nodejs/node#57698
* src: improve thread safety of TaskQueue
nodejs/node#57910
* buffer: define global v8::CFunction objects as const
nodejs/node#57676
* src: disable abseil deadlock detection
nodejs/node#57582
* zlib: fix pointer alignment
nodejs/node#57727
* chore: fixup patch indices
* src: set default config as node.config.json
nodejs/node#57171
* src: update std::vector<v8::Local<T>> to use v8::LocalVector<T>
nodejs/node#57578
* test: disable chmod tests failing in Docker
nodejs/node#58326
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
@marco-ippolito

Copy link
Copy Markdown
Member

This commit requires a manual backport to land on v20.x

codebytere added a commit to electron/electron that referenced this pull request Jun 6, 2025
@ghostghost mentioned this pull request Jun 8, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 18, 2025
codebytere added a commit to electron/electron that referenced this pull request Jun 30, 2025
* chore: bump node in DEPS to v22.16.0
* crypto: remove BoringSSL dh-primes addition
nodejs/node#57023
* tools: enable linter in test/fixtures/test\-runner/output
nodejs/node#57698
* src: improve thread safety of TaskQueue
nodejs/node#57910
* buffer: define global v8::CFunction objects as const
nodejs/node#57676
* zlib: fix pointer alignment
nodejs/node#57727
* chore: fixup patch indices
* src: set default config as node.config.json
nodejs/node#57171
* src: update std::vector<v8::Local<T>> to use v8::LocalVector<T>
nodejs/node#57578
* test: disable chmod tests failing in Docker
nodejs/node#58326
* chore: fix out of date patch
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
* chore: bump node in DEPS to v22.16.0
* crypto: remove BoringSSL dh-primes addition
nodejs/node#57023
* tools: enable linter in test/fixtures/test\-runner/output
nodejs/node#57698
* src: improve thread safety of TaskQueue
nodejs/node#57910
* buffer: define global v8::CFunction objects as const
nodejs/node#57676
* src: disable abseil deadlock detection
nodejs/node#57582
* zlib: fix pointer alignment
nodejs/node#57727
* chore: fixup patch indices
* src: set default config as node.config.json
nodejs/node#57171
* src: update std::vector<v8::Local<T>> to use v8::LocalVector<T>
nodejs/node#57578
* test: disable chmod tests failing in Docker
nodejs/node#58326
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node.js 20 Upgrade: Segmentation Fault Core Dump During Pipeline Lage Build Step

9 participants

@codebytere@mcollina@nodejs-github-bot@lpinca@marco-ippolito@bnoordhuis@jasnell@joyeecheung@aduh95