Skip to content

fix(client-core): return null instead of undefined when query is cancelled by mutex#10274

Merged
ovr merged 4 commits intomasterfrom
fix-10261
Mar 2, 2026
Merged

fix(client-core): return null instead of undefined when query is cancelled by mutex#10274
ovr merged 4 commits intomasterfrom
fix-10261

Conversation

@igorlukanin
Copy link
Copy Markdown
Member

When multiple queries share the same mutexKey, newer queries invalidate older
ones. Previously, cancelled queries would resolve to undefined because
mutexPromise silently swallowed the MUTEX_ERROR without returning a value.

This caused issues in useCubeQuery where resultSet would unexpectedly reset
to undefined while isLoading remained false.

Changes:

  • Add MutexCancelledError class for explicit mutex cancellation handling
  • Update mutexPromise to throw MutexCancelledError instead of swallowing errors
  • Catch MutexCancelledError in loadMethod and return null (a valid return type)

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Issue Reference this PR resolves

Fixes #10261

Conversation with Claude

claude.txt

@igorlukanin igorlukanin requested a review from a team as a code owner December 22, 2025 10:58
@igorlukanin igorlukanin removed their assignment Dec 22, 2025
@github-actions github-actions bot added client:core Issues relating to the JavaScript client SDK javascript Pull requests that update Javascript code labels Dec 22, 2025
@johnhunter
Copy link
Copy Markdown

Thanks for looking into this @igorlukanin - I didn't have a good understanding of the mutex behaviour.

Copy link
Copy Markdown

@johnhunter johnhunter left a comment

Choose a reason for hiding this comment

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

Solution makes sense to me. Just the type fallout to resolve.

Copy link
Copy Markdown

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 PR addresses an issue where queries cancelled by mutex operations were resolving to undefined, causing unexpected behavior in components like useCubeQuery. The fix introduces explicit error handling for mutex cancellations and returns null instead.

Key changes:

  • Introduces MutexCancelledError class to explicitly represent mutex cancellation events
  • Updates mutexPromise function to throw MutexCancelledError instead of silently swallowing errors
  • Adds error handling in loadMethod to catch MutexCancelledError and return null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@KSDaemon KSDaemon removed their assignment Jan 16, 2026
@johnhunter
Copy link
Copy Markdown

Is this PR still active? The reported issue is #10261

@ovr ovr self-assigned this Feb 27, 2026
igorlukanin and others added 4 commits March 2, 2026 14:49
…elled by mutex

When multiple queries share the same mutexKey, newer queries invalidate older
  ones. Previously, cancelled queries would resolve to undefined because
  mutexPromise silently swallowed the MUTEX_ERROR without returning a value.

  This caused issues in useCubeQuery where resultSet would unexpectedly reset
  to undefined while isLoading remained false.

  Changes:
  - Add MutexCancelledError class for explicit mutex cancellation handling
  - Update mutexPromise to throw MutexCancelledError instead of swallowing errors
  - Catch MutexCancelledError in loadMethod and return null (a valid return type)

  Fixes #10261
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.64%. Comparing base (2e019d4) to head (455b602).
⚠️ Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10274      +/-   ##
==========================================
+ Coverage   57.56%   57.64%   +0.07%     
==========================================
  Files         222      222              
  Lines       17390    17392       +2     
  Branches     3561     3561              
==========================================
+ Hits        10011    10026      +15     
+ Misses       6843     6828      -15     
- Partials      536      538       +2     
Flag Coverage Δ
cube-backend 57.64% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ovr ovr merged commit ea6b3e7 into master Mar 2, 2026
36 checks passed
@ovr ovr deleted the fix-10261 branch March 2, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client:core Issues relating to the JavaScript client SDK javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@cubejs-client/react cubeApi.load sometimes resolves to undefined - overwriting the resultSet from useCubeQuery

6 participants