diff --git a/.changeset/orange-comics-buy.md b/.changeset/orange-comics-buy.md new file mode 100644 index 000000000..01c2a0252 --- /dev/null +++ b/.changeset/orange-comics-buy.md @@ -0,0 +1,6 @@ +--- +'@powersync/service-core': patch +'@powersync/service-image': patch +--- + +Fix sync rule clearing process to not block sync rule processing. diff --git a/packages/service-core/src/replication/AbstractReplicator.ts b/packages/service-core/src/replication/AbstractReplicator.ts index 6cb7a3d30..b102350d9 100644 --- a/packages/service-core/src/replication/AbstractReplicator.ts +++ b/packages/service-core/src/replication/AbstractReplicator.ts @@ -1,14 +1,14 @@ import { container, logger } from '@powersync/lib-services-framework'; +import { ReplicationMetric } from '@powersync/service-types'; import { hrtime } from 'node:process'; import winston from 'winston'; +import { MetricsEngine } from '../metrics/MetricsEngine.js'; import * as storage from '../storage/storage-index.js'; import { StorageEngine } from '../storage/storage-index.js'; import { SyncRulesProvider } from '../util/config/sync-rules/sync-rules-provider.js'; import { AbstractReplicationJob } from './AbstractReplicationJob.js'; import { ErrorRateLimiter } from './ErrorRateLimiter.js'; import { ConnectionTestResult } from './ReplicationModule.js'; -import { MetricsEngine } from '../metrics/MetricsEngine.js'; -import { ReplicationMetric } from '@powersync/service-types'; // 5 minutes const PING_INTERVAL = 1_000_000_000n * 300n; @@ -40,9 +40,17 @@ export abstract class AbstractReplicator(); + + /** + * Map of sync rule ids to promises that are clearing the sync rule configuration. + * + * We primarily do this to keep track of what we're currently clearing, but don't currently + * use the Promise value. + */ + private clearingJobs = new Map>(); + /** * Used for replication lag computation. */ @@ -242,16 +250,26 @@ export abstract class AbstractReplicator { + this.logger.warn(`Failed clean up replication config for sync rule: ${syncRules.id}`, e); + }) + .finally(() => { + this.clearingJobs.delete(syncRules.id); + }); + this.clearingJobs.set(syncRules.id, promise); } } @@ -261,6 +279,8 @@ export abstract class AbstractReplicator