Skip to content

fix: Duplicate session destruction can cause unhandled promise rejection#10319

Merged
mtrezza merged 1 commit intoparse-community:alphafrom
mtrezza:fix/destroy-error-destroyDuplicatedSessions
Mar 26, 2026
Merged

fix: Duplicate session destruction can cause unhandled promise rejection#10319
mtrezza merged 1 commit intoparse-community:alphafrom
mtrezza:fix/destroy-error-destroyDuplicatedSessions

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Mar 26, 2026

Issue

destroyDuplicatedSessions in RestWrite.js calls database.destroy() without returning the promise (fire-and-forget). This causes unhandled promise rejections when the database operation fails, which in modern Node.js terminates the process by default. It also causes flaky tests when reconfigureServer() tears down the database while the background destroy is still pending.

Approach

  • Return the database.destroy() promise from destroyDuplicatedSessions so it is properly awaited in the RestWrite execute chain
  • Catch OBJECT_NOT_FOUND errors since having no duplicate sessions to delete is a normal condition
  • Remove the polling workaround in ParseUser.spec.js that was compensating for the fire-and-forget pattern

Tasks

  • Add tests

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where duplicate sessions could be created for a user/installation pair during login operations, ensuring only a single session is created and properly handled in error scenarios.

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: destroyDuplicatedSessions fix: DestroyDuplicatedSessions Mar 26, 2026
@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 26, 2026

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement.

@parseplatformorg
Copy link
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99ab4e83-0405-4424-b0d0-42087a53541e

📥 Commits

Reviewing files that changed from the base of the PR and between eea27af and 9ac62c4.

📒 Files selected for processing (2)
  • spec/ParseUser.spec.js
  • src/RestWrite.js

📝 Walkthrough

Walkthrough

The changes ensure duplicate sessions are reliably destroyed during user creation by making destroyDuplicatedSessions return a Promise and properly handle cleanup errors. The test is updated to remove polling logic, relying instead on the Promise-based cleanup to complete synchronously before assertions.

Changes

Cohort / File(s) Summary
Test cleanup
spec/ParseUser.spec.js
Removed retry/polling loop that waited for async session cleanup. Test now performs single find call and directly asserts cleanup results.
Promise-based cleanup
src/RestWrite.js
destroyDuplicatedSessions now returns database.destroy() Promise with .catch() handler that swallows OBJECT_NOT_FOUND errors while rethrowing others.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • test: Fix flaky tests #10313: Directly related — this PR adds async polling/waiting for duplicate session cleanup in the same test, while the main PR removes polling and returns a Promise from the cleanup method to ensure synchronous completion.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing unhandled promise rejections from duplicate session destruction by ensuring the promise is returned and handled properly.
Description check ✅ Passed The description covers the issue, approach, and task completion; it is missing documentation and security check tasks which are only recommended for some changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.41.1)
spec/ParseUser.spec.js

[]


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@mtrezza mtrezza changed the title fix: DestroyDuplicatedSessions fix: Await duplicate session destruction to prevent unhandled promise rejection Mar 26, 2026
@mtrezza mtrezza changed the title fix: Await duplicate session destruction to prevent unhandled promise rejection fix: Duplicate session destruction can cause unhandled promise rejection Mar 26, 2026
@codecov
Copy link

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.52%. Comparing base (eea27af) to head (9ac62c4).
⚠️ Report is 2 commits behind head on alpha.

Files with missing lines Patch % Lines
src/RestWrite.js 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10319      +/-   ##
==========================================
- Coverage   92.53%   92.52%   -0.01%     
==========================================
  Files         192      192              
  Lines       16502    16504       +2     
  Branches      227      227              
==========================================
+ Hits        15270    15271       +1     
- Misses       1212     1213       +1     
  Partials       20       20              

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

@mtrezza mtrezza merged commit 92791c1 into parse-community:alpha Mar 26, 2026
23 of 24 checks passed
parseplatformorg pushed a commit that referenced this pull request Mar 26, 2026
# [9.7.0-alpha.6](9.7.0-alpha.5...9.7.0-alpha.6) (2026-03-26)

### Bug Fixes

* Duplicate session destruction can cause unhandled promise rejection ([#10319](#10319)) ([92791c1](92791c1))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 9.7.0-alpha.6

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants