diff --git a/.changeset/orange-forks-eat.md b/.changeset/orange-forks-eat.md new file mode 100644 index 000000000..b25796e37 --- /dev/null +++ b/.changeset/orange-forks-eat.md @@ -0,0 +1,5 @@ +--- +'@powersync/service-core': patch +--- + +Fix liveness probe when no connections are defined. diff --git a/packages/service-core/src/replication/ReplicationEngine.ts b/packages/service-core/src/replication/ReplicationEngine.ts index 3ae7849d8..9ef584e18 100644 --- a/packages/service-core/src/replication/ReplicationEngine.ts +++ b/packages/service-core/src/replication/ReplicationEngine.ts @@ -1,9 +1,10 @@ -import { logger } from '@powersync/lib-services-framework'; +import { container, logger } from '@powersync/lib-services-framework'; import { AbstractReplicator } from './AbstractReplicator.js'; import { ConnectionTestResult } from './ReplicationModule.js'; export class ReplicationEngine { private readonly replicators: Map = new Map(); + private probeInterval: NodeJS.Timeout | null = null; /** * Register a Replicator with the engine @@ -27,6 +28,17 @@ export class ReplicationEngine { logger.info(`Starting Replicator: ${replicator.id}`); replicator.start(); } + if (this.replicators.size == 0) { + // If a replicator is running, the replicators update the probes. + // If no connections are configured, then no replicator is running + // Typical when no connections are configured. + // In this case, update the probe here to avoid liveness probe failures. + this.probeInterval = setInterval(() => { + container.probes.touch().catch((e) => { + logger.error(`Failed to touch probe`, e); + }); + }, 5_000); + } logger.info('Successfully started Replication Engine.'); } @@ -39,6 +51,9 @@ export class ReplicationEngine { logger.info(`Stopping Replicator: ${replicator.id}`); await replicator.stop(); } + if (this.probeInterval) { + clearInterval(this.probeInterval); + } logger.info('Successfully shut down Replication Engine.'); }