8000 fix: unexpected null pointer exception due to race condition by JounQin · Pull Request #245 · un-ts/synckit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: unexpected null pointer exception due to race condition #245

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

Merged
merged 1 commit into from
May 30, 2025

Conversation

JounQin
Copy link
Member
@JounQin JounQin commented May 30, 2025

related #217


Important

Fixes race condition in startWorkerThread and adds reliability test in synckit.

  • Behavior:
    • Fixes a race condition causing null pointer exceptions in startWorkerThread in src/index.ts by checking for undefined messages.
    • Adds a reliability test reliability.spec.ts to run 1 million iterations of a sync function to ensure stability.
  • Configuration:
    • Updates package.json to change ignoreFiles from **/*.d.ts to lib for type coverage.
  • Documentation:
    • Adds a changeset shiny-kids-check.md to document the patch fix for the race condition.

This description was created by Ellipsis for ad8572b. You can customize this summary. It will automatically update as commits are pushed.

@JounQin JounQin requested a review from Copilot May 30, 2025 03:59
@JounQin JounQin self-assigned this May 30, 2025
@JounQin JounQin added bug Something isn't working dependencies labels May 30, 2025
Copy link
changeset-bot bot commented May 30, 2025

🦋 Changeset detected

Latest commit: ad8572b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
synckit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor
coderabbitai bot commented May 30, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
8000

Copy link

Walkthrough

This pull request introduces changes to allow releases on the 0.10.x branch. It includes a fix for a null pointer exception due to a race condition, updates to the package.json configuration, and adds new test files to ensure reliability.

Changes

File Summary
.changeset/shiny-kids-check.md Added changeset for patching a null pointer exception issue.
package.json Modified ignoreFiles configuration from **/*.d.ts to lib.
src/index.ts Refactored message receiving logic to handle undefined results and prevent null pointer exceptions.
test/reliability.spec.ts, test/worker-identity.js Added new test files for reliability testing and worker identity verification.

@JounQin JounQin changed the title ci: allow releasing on 0.10.x branch fix: unexpected null pointer exception due to race condition May 30, 2025
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enables CI releases on the 0.10.x branch and addresses a race condition leading to unexpected null pointer exceptions in worker message handling.

  • Introduces a new worker identity used by the runAsWorker function.
  • Adds a reliability test that repeatedly verifies the worker’s identity function.
  • Modifies the logic for receiving worker messages in src/index.ts to better handle potential race conditions and updates the package ignore files.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/worker-identity.js New test worker using runAsWorker with a basic identity function
test/reliability.spec.ts Adds a high-volume reliability test using createSyncFn
src/index.ts Updates message handling to address race condition issues
package.json Updates ignoreFiles configuration
.changeset/shiny-kids-check.md Adds a changeset documenting the fix for the race condition
Comments suppressed due to low confidence (1)

package.json:144

  • Verify that changing ignoreFiles from "**/*.d.ts" to "lib" is intentional, and that it won't inadvertently affect the handling of declaration files.
"lib"

Copy link

Copy link
@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to ad8572b in 1 minute and 39 seconds. Click for details.
  • Reviewed 92 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .changeset/shiny-kids-check.md:5
  • Draft comment:
    Clarify the race condition fix details for better context.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking for clarification on a race condition fix, which is not allowed as it falls under asking the PR author to explain or confirm their intention. This violates the rules.
2. package.json:144
  • Draft comment:
    Verify that ignoring the entire 'lib' directory (instead of '*.d.ts') for type coverage is intentional.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the author to confirm their intention regarding ignoring the entire lib directory for type coverage. This falls under the rule of not asking the PR author to confirm their intention or to ensure the behavior is intended. Therefore, this comment should be removed.
3. src/index.ts:664
  • Draft comment:
    Consider replacing the recursive call in receiveMessageWithId with an iterative approach to avoid potential stack overflow on repeated unexpected messages.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50% The recursive call is part of the changed code, as the diff shows the addition of the msg?.id null check and the recursive call. The suggestion to use iteration instead of recursion is a valid performance/safety concern since deep recursion can cause stack overflow. However, in this case, the recursion is unlikely to go very deep since it only recurses when receiving out-of-order messages, which should be rare. The current implementation is also clearer and easier to understand than an iterative version would be. I may be underestimating the frequency of out-of-order messages in a real-world scenario. If messages frequently arrive out of order, the recursion depth could become problematic. Even if messages do arrive out of order somewhat frequently, the recursion would only go as deep as the number of out-of-order messages, which is naturally limited by the messaging system. A stack overflow seems very unlikely in practice. While technically correct, this suggestion addresses a theoretical issue that is unlikely to cause problems in practice. The current recursive implementation is clearer and the risk of stack overflow is minimal.
4. test/reliability.spec.ts:5
  • Draft comment:
    High iteration count (1e6 runs) in the reliability test; ensure it only runs in CI to avoid local performance issues.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_1SBLTXop8Mldz0We

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.85%. Comparing base (d6716bd) to head (ad8572b).
Report is 2 commits behind head on 0.10.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           0.10.x     #245      +/-   ##
==========================================
+ Coverage   86.80%   86.85%   +0.04%     
==========================================
  Files           1        1              
  Lines         288      289       +1     
  Branches      137      138       +1     
==========================================
+ Hits          250      251       +1     
- Misses         31       38       +7     
+ Partials        7        0       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Copy link
Contributor

📊 Package size report   0.5%↑

File Before After
lib/index.cjs 20.4 kB 0.6%↑20.5 kB
lib/index.js 18.9 kB 0.9%↑19.0 kB
lib/index.js.map 18.1 kB 0.8%↑18.2 kB
package.json 4.0 kB -0.15%↓4.0 kB
Total (Includes all files) 81.9 kB 0.5%↑82.3 kB
Tarball size 20.4 kB 0.5%↑20.4 kB
Unchanged files
File Size
index.d.cts 60 B
lib/index.d.ts 2.4 kB
lib/types.d.ts 1.1 kB
lib/types.js 44 B
lib/types.js.map 102 B
LICENSE 1.1 kB
README.md 15.8 kB

🤖 This report was automatically generated by pkg-size-action

Copy link
pkg-pr-new bot commented May 30, 2025

Open in StackBlitz

npm i https://pkg.pr.new/un-ts/synckit@245

commit: ad8572b

@JounQin JounQin merged commit bc77666 into 0.10.x May 30, 2025
42 checks passed
@JounQin JounQin deleted the fix/message branch May 30, 2025 04:20
@JounQin JounQin mentioned this pull request May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0