Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-cobras-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-module-mongodb': patch
---

Use short timeout for testing mongodb connections.
9 changes: 7 additions & 2 deletions modules/module-mongodb/src/module/MongoModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ export class MongoModule extends replication.ReplicationModule<types.MongoConnec
async testConnection(config: types.MongoConnectionConfig): Promise<void> {
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();
}
Expand Down
8 changes: 6 additions & 2 deletions modules/module-mongodb/src/replication/MongoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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, {});
}
Expand Down
2 changes: 1 addition & 1 deletion modules/module-postgres/src/module/PostgresModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class PostgresModule extends replication.ReplicationModule<types.Postgres
});
const connection = await connectionManager.snapshotConnection();
try {
return checkSourceConfiguration(connection, PUBLICATION_NAME);
return await checkSourceConfiguration(connection, PUBLICATION_NAME);
} finally {
await connectionManager.end();
}
Expand Down
Loading