diff --git a/.changeset/moody-cobras-walk.md b/.changeset/moody-cobras-walk.md new file mode 100644 index 000000000..0aaf1cc3f --- /dev/null +++ b/.changeset/moody-cobras-walk.md @@ -0,0 +1,5 @@ +--- +'@powersync/service-module-mongodb': patch +--- + +Use short timeout for testing mongodb connections. diff --git a/modules/module-mongodb/src/module/MongoModule.ts b/modules/module-mongodb/src/module/MongoModule.ts index bbd9ab869..e50c77025 100644 --- a/modules/module-mongodb/src/module/MongoModule.ts +++ b/modules/module-mongodb/src/module/MongoModule.ts @@ -55,9 +55,14 @@ export class MongoModule extends replication.ReplicationModule { this.decodeConfig(config); const normalisedConfig = this.resolveConfig(this.decodedConfig!); - const connectionManager = new MongoManager(normalisedConfig); + const connectionManager = new MongoManager(normalisedConfig, { + // Use short timeouts for testing connections. + // Must be < 30s, to ensure we get a proper timeout error. + socketTimeoutMS: 5_000, + serverSelectionTimeoutMS: 5_000 + }); try { - return checkSourceConfiguration(connectionManager); + return await checkSourceConfiguration(connectionManager); } finally { await connectionManager.end(); } diff --git a/modules/module-mongodb/src/replication/MongoManager.ts b/modules/module-mongodb/src/replication/MongoManager.ts index cb2f9d54f..f005d696e 100644 --- a/modules/module-mongodb/src/replication/MongoManager.ts +++ b/modules/module-mongodb/src/replication/MongoManager.ts @@ -8,7 +8,10 @@ export class MongoManager { public readonly client: mongo.MongoClient; public readonly db: mongo.Db; - constructor(public options: NormalizedMongoConnectionConfig) { + constructor( + public options: NormalizedMongoConnectionConfig, + overrides?: mongo.MongoClientOptions + ) { // The pool is lazy - no connections are opened until a query is performed. this.client = new mongo.MongoClient(options.uri, { auth: { @@ -28,7 +31,8 @@ export class MongoManager { maxPoolSize: 8, maxConnecting: 3, - maxIdleTimeMS: 60_000 + maxIdleTimeMS: 60_000, + ...overrides }); this.db = this.client.db(options.database, {}); } diff --git a/modules/module-postgres/src/module/PostgresModule.ts b/modules/module-postgres/src/module/PostgresModule.ts index f7bbf0453..53e79e541 100644 --- a/modules/module-postgres/src/module/PostgresModule.ts +++ b/modules/module-postgres/src/module/PostgresModule.ts @@ -133,7 +133,7 @@ export class PostgresModule extends replication.ReplicationModule