Skip to content

Conversation

@rkistner
Copy link
Contributor

Specify a limit of 40s for each query, instead of relying on the connection socket timeout. The most common cause is a timeout when computing checksums on buckets with millions of operations. We can often recover by retrying the query - the second attempt is faster since the data would be cached in database memory.

Before:

[PSYNC_2001] Something went wrong
  connection 10 to a.b.c.d:27017 timed out

Now:

[PSYNC_S2403] Query timed out while reading checksums

@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2025

🦋 Changeset detected

Latest commit: 87bcc78

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

This PR includes changesets to release 16 packages
Name Type
@powersync/service-module-mongodb-storage Patch
@powersync/service-errors Patch
@powersync/lib-service-mongodb Patch
@powersync/service-core Patch
@powersync/service-image Patch
@powersync/service-schema Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres Patch
@powersync/lib-services-framework Patch
@powersync/service-core-tests Patch
@powersync/service-module-core Patch
@powersync/service-module-postgres-storage Patch
test-client Patch
@powersync/service-rsocket-router Patch
@powersync/lib-service-postgres 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

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 improves error handling for MongoDB storage queries by implementing explicit query timeouts to prevent connection timeouts. The key changes include adding a 40-second timeout limit for MongoDB operations and providing more descriptive error messages when timeouts occur.

Key changes:

  • Added maxTimeMS parameter to MongoDB queries to prevent connection socket timeouts
  • Implemented specific error handling for query timeouts with new error codes and messages
  • Increased the operation timeout from 30 seconds to 40 seconds

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/service-errors/src/errors.ts Added new DatabaseQueryError class for handling database query-specific errors
packages/service-errors/src/codes.ts Added new error codes PSYNC_S2403 and PSYNC_S2404 for query timeout and failure scenarios
modules/module-mongodb-storage/src/storage/implementation/MongoSyncBucketStorage.ts Added maxTimeMS parameter to MongoDB operations and error handling for bucket data and checksum queries
libs/lib-mongodb/src/db/mongo.ts Increased MONGO_OPERATION_TIMEOUT_MS from 30 seconds to 40 seconds
libs/lib-mongodb/src/db/errors.ts Added mapQueryError function to handle query-specific error mapping
.changeset/dull-pumas-punch.md Added changeset documentation for the MongoDB storage error message improvements

Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

Looks good to me :)

@rkistner rkistner merged commit a60f2c7 into main Jul 16, 2025
21 checks passed
@rkistner rkistner deleted the mongo-query-timeouts branch July 16, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants