Skip to content

Commit 0ace0d3

Browse files
authored
Fix liveness probe when no connections are defined (#401)
* Fix liveness probe when no connections are defined. * Add changeset.
1 parent d889219 commit 0ace0d3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.changeset/orange-forks-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/service-core': patch
3+
---
4+
5+
Fix liveness probe when no connections are defined.

packages/service-core/src/replication/ReplicationEngine.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { logger } from '@powersync/lib-services-framework';
1+
import { container, logger } from '@powersync/lib-services-framework';
22
import { AbstractReplicator } from './AbstractReplicator.js';
33
import { ConnectionTestResult } from './ReplicationModule.js';
44

55
export class ReplicationEngine {
66
private readonly replicators: Map<string, AbstractReplicator> = new Map();
7+
private probeInterval: NodeJS.Timeout | null = null;
78

89
/**
910
* Register a Replicator with the engine
@@ -27,6 +28,17 @@ export class ReplicationEngine {
2728
logger.info(`Starting Replicator: ${replicator.id}`);
2829
replicator.start();
2930
}
31+
if (this.replicators.size == 0) {
32+
// If a replicator is running, the replicators update the probes.
33+
// If no connections are configured, then no replicator is running
34+
// Typical when no connections are configured.
35+
// In this case, update the probe here to avoid liveness probe failures.
36+
this.probeInterval = setInterval(() => {
37+
container.probes.touch().catch((e) => {
38+
logger.error(`Failed to touch probe`, e);
39+
});
40+
}, 5_000);
41+
}
3042
logger.info('Successfully started Replication Engine.');
3143
}
3244

@@ -39,6 +51,9 @@ export class ReplicationEngine {
3951
logger.info(`Stopping Replicator: ${replicator.id}`);
4052
await replicator.stop();
4153
}
54+
if (this.probeInterval) {
55+
clearInterval(this.probeInterval);
56+
}
4257
logger.info('Successfully shut down Replication Engine.');
4358
}
4459

0 commit comments

Comments
 (0)