[Fix] Mongo Server Error Detection #177
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
#136 Moved common MongoDB logic to the
@powersync/lib-service-mongodb
package.The bucket storage module's MongoDB connection is created using a utility from the shared library. The storage implementation checks certain caught
Error
s if they are instances of the MongoDBMongoServerError
class. Theinstanceof
checks fail if the shared library and the storage module use different versions of the MongoDB package. The core repository uses the same version throughout, but the hosted version's lockfile resolved different versions which caused the error detection to fail. Luckily the affected processes are retried, which did not cause any major issues.This PR addresses the issue via two methods.
A
isMongoServerError
utility function is now exported from@powersync/lib-service-mongodb
. Theinstanceof
check in this function should pass if the connection was created from the shared library. Additionally a fallback check is added by checking theError
prototypename
field - this should detect the error type even if a different MongoDB package spawned the connection or error.The direct
mongodb
NPM package dependency has been removed from the MongoDB replicator and storage modules. The shared MongoDB library now re-exports it'smongodb
dependency.Testing
Development packages were released and locally installed in the hosted repository. A sync rule change was applied which triggered the termination of previous sync rules. Sync rules were correctly terminated with no error logs.
Before:

After:

The MongoDB replicator was also smoke tested locally.