@powersync/lib-service-postgres 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @powersync/lib-service-postgres
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 123c801: Reconnect PostgreSQL notification connections and restore `LISTEN` subscriptions when the underlying connection is terminated. Harden connection-slot retries and lease handling, and publish checkpoint notifications atomically with checkpoint updates.
8
+ - Updated dependencies [2189250]
9
+ - Updated dependencies [123c801]
10
+ - @powersync/lib-services-framework@0.10.0
11
+ - @powersync/service-types@0.17.0
12
+ - @powersync/service-jpgwire@0.21.22
13
+
14
+ ## 0.5.2
15
+
16
+ ### Patch Changes
17
+
18
+ - @powersync/lib-services-framework@0.9.8
19
+ - @powersync/service-jpgwire@0.21.21
20
+
3
21
  ## 0.5.1
4
22
 
5
23
  ### Patch Changes
@@ -1,10 +1,23 @@
1
1
  import * as framework from '@powersync/lib-services-framework';
2
2
  import * as pgwire from '@powersync/service-jpgwire';
3
+ export type NotificationEvent = {
4
+ type: 'notification';
5
+ notification: pgwire.PgNotification;
6
+ } | {
7
+ type: 'channels-registered';
8
+ } | {
9
+ type: 'connection-error';
10
+ error: unknown;
11
+ };
3
12
  export interface NotificationListener {
4
- notification?: (payload: pgwire.PgNotification) => void;
13
+ /**
14
+ * Reports notifications and notification-connection lifecycle events.
15
+ */
16
+ notificationEvent?: (event: NotificationEvent) => void;
5
17
  }
6
18
  export interface ConnectionSlotListener extends NotificationListener {
7
19
  connectionAvailable?: () => void;
20
+ /** Reports that this slot exhausted its connection attempts. */
8
21
  connectionError?: (exception: any) => void;
9
22
  connectionCreated?: (connection: pgwire.PgConnection) => Promise<void>;
10
23
  }
@@ -20,22 +33,23 @@ export type ConnectionSlotOptions = {
20
33
  export declare const MAX_CONNECTION_ATTEMPTS = 5;
21
34
  export declare class ConnectionSlot extends framework.BaseObserver<ConnectionSlotListener> {
22
35
  protected options: ConnectionSlotOptions;
23
- isAvailable: boolean;
24
36
  isPoking: boolean;
25
37
  closed: boolean;
26
38
  protected connection: pgwire.PgConnection | null;
27
39
  protected connectingPromise: Promise<pgwire.PgConnection> | null;
40
+ protected activeLease: symbol | null;
28
41
  constructor(options: ConnectionSlotOptions);
29
42
  get isConnected(): boolean;
30
- protected connect(): Promise<pgwire.PgConnection>;
43
+ get isAvailable(): boolean;
31
44
  [Symbol.asyncDispose](): Promise<void>;
32
- protected configureConnectionNotifications(connection: pgwire.PgConnection): Promise<void>;
33
- protected handleNotification: (payload: pgwire.PgNotification) => void;
34
- protected hasNotificationListener(): boolean;
35
45
  /**
36
- * Test the connection if it can be reached.
46
+ * Ensure this slot has a connection and signal when it can be leased.
37
47
  */
38
48
  poke(): Promise<void>;
39
- protected setAvailable(): void;
49
+ protected connect(): Promise<pgwire.PgConnection>;
50
+ protected handleConnectionDestroyed(connection: pgwire.PgConnection): void;
51
+ protected configureConnectionNotifications(connection: pgwire.PgConnection): Promise<void>;
52
+ protected handleNotification: (payload: pgwire.PgNotification) => void;
53
+ protected notifyConnectionAvailable(): void;
40
54
  lock(): ConnectionLease | null;
41
55
  }
@@ -1,39 +1,29 @@
1
1
  import * as framework from '@powersync/lib-services-framework';
2
2
  import * as pgwire from '@powersync/service-jpgwire';
3
+ import * as timers from 'node:timers/promises';
3
4
  export const MAX_CONNECTION_ATTEMPTS = 5;
5
+ const CONNECTION_RETRY_DELAY_MS = 100;
4
6
  export class ConnectionSlot extends framework.BaseObserver {
5
7
  options;
6
- isAvailable;
7
8
  isPoking;
8
9
  closed;
9
10
  connection;
10
11
  connectingPromise;
12
+ activeLease;
11
13
  constructor(options) {
12
14
  super();
13
15
  this.options = options;
14
- this.isAvailable = false;
15
16
  this.connection = null;
16
17
  this.isPoking = false;
17
18
  this.connectingPromise = null;
19
+ this.activeLease = null;
18
20
  this.closed = false;
19
21
  }
20
22
  get isConnected() {
21
23
  return !!this.connection;
22
24
  }
23
- async connect() {
24
- this.connectingPromise = pgwire.connectPgWire(this.options.config, {
25
- type: 'standard',
26
- applicationName: this.options.applicationName
27
- });
28
- const connection = await this.connectingPromise;
29
- this.connectingPromise = null;
30
- await this.iterateAsyncListeners(async (l) => l.connectionCreated?.(connection));
31
- /**
32
- * Configure the Postgres connection to listen to notifications.
33
- * Subscribing to notifications, even without a registered listener, should not add much overhead.
34
- */
35
- await this.configureConnectionNotifications(connection);
36
- return connection;
25
+ get isAvailable() {
26
+ return this.connection != null && this.activeLease == null && !this.closed;
37
27
  }
38
28
  async [Symbol.asyncDispose]() {
39
29
  this.closed = true;
@@ -41,75 +31,150 @@ export class ConnectionSlot extends framework.BaseObserver {
41
31
  await connection?.end();
42
32
  super.clearListeners();
43
33
  }
44
- async configureConnectionNotifications(connection) {
45
- connection.onnotification = this.handleNotification;
46
- for (const channelName of this.options.notificationChannels ?? []) {
47
- await connection.query({
48
- statement: `LISTEN ${channelName}`
49
- });
50
- }
51
- }
52
- handleNotification = (payload) => {
53
- if (!this.options.notificationChannels?.includes(payload.channel)) {
54
- return;
55
- }
56
- this.iterateListeners((l) => l.notification?.(payload));
57
- };
58
- hasNotificationListener() {
59
- return !!Object.values(this.listeners).find((l) => !!l.notification);
60
- }
61
34
  /**
62
- * Test the connection if it can be reached.
35
+ * Ensure this slot has a connection and signal when it can be leased.
63
36
  */
64
37
  async poke() {
65
- if (this.isPoking || (this.isConnected && this.isAvailable == false) || this.closed) {
38
+ if (this.closed || this.connection || this.isPoking) {
66
39
  return;
67
40
  }
68
41
  this.isPoking = true;
69
- for (let retryCounter = 0; retryCounter <= MAX_CONNECTION_ATTEMPTS; retryCounter++) {
70
- try {
71
- const connection = this.connection ?? (await this.connect());
72
- await connection.query({
73
- statement: 'SELECT 1'
74
- });
75
- if (!this.connection) {
42
+ try {
43
+ for (let retryCounter = 0; retryCounter <= MAX_CONNECTION_ATTEMPTS; retryCounter++) {
44
+ try {
45
+ const connection = await this.connect();
46
+ if (this.closed) {
47
+ connection.destroy();
48
+ return;
49
+ }
76
50
  this.connection = connection;
77
- this.setAvailable();
51
+ // Register this only after the slot owns the connection. If
52
+ // `whenDestroyed` has already settled, its callback runs in a later
53
+ // microtask and must see this exact connection assigned. Registering
54
+ // it before assignment could ignore the destruction and leave the
55
+ // slot holding an already-destroyed connection.
56
+ connection.whenDestroyed
57
+ .catch((error) => framework.logger.debug('Postgres connection destroyed with an error', error))
58
+ .then(() => this.handleConnectionDestroyed(connection));
59
+ if (this.activeLease == null) {
60
+ this.notifyConnectionAvailable();
61
+ }
62
+ break;
78
63
  }
79
- else if (this.isAvailable) {
80
- this.iterateListeners((cb) => cb.connectionAvailable?.());
64
+ catch (ex) {
65
+ if (retryCounter >= MAX_CONNECTION_ATTEMPTS) {
66
+ this.iterateListeners((cb) => {
67
+ cb.connectionError?.(ex);
68
+ cb.notificationEvent?.({ type: 'connection-error', error: ex });
69
+ });
70
+ }
71
+ else {
72
+ await timers.setTimeout(CONNECTION_RETRY_DELAY_MS);
73
+ if (this.closed) {
74
+ return;
75
+ }
76
+ }
81
77
  }
82
- // Connection is alive and healthy
83
- break;
84
78
  }
85
- catch (ex) {
86
- // Should be valid for all cases
87
- this.isAvailable = false;
88
- if (this.connection) {
89
- this.connection.onnotification = () => { };
90
- this.connection.destroy();
91
- this.connection = null;
92
- }
93
- if (retryCounter >= MAX_CONNECTION_ATTEMPTS) {
94
- this.iterateListeners((cb) => cb.connectionError?.(ex));
95
- }
79
+ }
80
+ finally {
81
+ this.isPoking = false;
82
+ }
83
+ }
84
+ async connect() {
85
+ // Only allow a single connect to run at-a-time
86
+ if (this.connectingPromise) {
87
+ return this.connectingPromise;
88
+ }
89
+ const connectInternal = async () => {
90
+ let connection = null;
91
+ try {
92
+ const connected = await pgwire.connectPgWire(this.options.config, {
93
+ type: 'standard',
94
+ applicationName: this.options.applicationName
95
+ });
96
+ connection = connected;
97
+ await this.iterateAsyncListeners(async (l) => l.connectionCreated?.(connected));
98
+ /**
99
+ * Configure the Postgres connection to listen to notifications.
100
+ * Subscribing to notifications, even without a registered listener, should not add much overhead.
101
+ */
102
+ await this.configureConnectionNotifications(connected);
103
+ return connected;
96
104
  }
105
+ catch (error) {
106
+ connection?.destroy();
107
+ throw error;
108
+ }
109
+ };
110
+ this.connectingPromise = connectInternal();
111
+ try {
112
+ return await this.connectingPromise;
113
+ }
114
+ finally {
115
+ this.connectingPromise = null;
116
+ }
117
+ }
118
+ handleConnectionDestroyed(connection) {
119
+ // Guard that the closed connection is actually the one in use by the slot.
120
+ if (this.connection != connection) {
121
+ return;
122
+ }
123
+ // Clear the slot reference, marking the slot as unavailable
124
+ this.connection = null;
125
+ // Notification slots must restore their LISTEN subscriptions immediately.
126
+ // Other slots reconnect lazily when the next lease is requested.
127
+ if (!this.closed && this.options.notificationChannels?.length) {
128
+ this.poke().catch((error) => framework.logger.error('Failed to restore Postgres notification connection', error));
97
129
  }
98
- this.isPoking = false;
99
130
  }
100
- setAvailable() {
101
- this.isAvailable = true;
131
+ async configureConnectionNotifications(connection) {
132
+ connection.onnotification = this.handleNotification;
133
+ const notificationChannels = this.options.notificationChannels ?? [];
134
+ for (const channelName of notificationChannels) {
135
+ await connection.query({
136
+ statement: `LISTEN ${channelName}`
137
+ });
138
+ }
139
+ if (notificationChannels.length > 0) {
140
+ this.iterateListeners((l) => l.notificationEvent?.({ type: 'channels-registered' }));
141
+ }
142
+ }
143
+ handleNotification = (payload) => {
144
+ if (!this.options.notificationChannels?.includes(payload.channel)) {
145
+ return;
146
+ }
147
+ this.iterateListeners((l) => l.notificationEvent?.({ type: 'notification', notification: payload }));
148
+ };
149
+ notifyConnectionAvailable() {
102
150
  this.iterateListeners((l) => l.connectionAvailable?.());
103
151
  }
104
152
  lock() {
105
- if (!this.isAvailable || !this.connection || this.closed) {
153
+ if (!this.isAvailable || !this.connection || this.activeLease != null || this.closed) {
106
154
  return null;
107
155
  }
108
- this.isAvailable = false;
156
+ // Create a unique symbol to identify this lease
157
+ const lease = Symbol();
158
+ this.activeLease = lease;
109
159
  return {
110
160
  connection: this.connection,
111
161
  release: () => {
112
- this.setAvailable();
162
+ // Only release if this lease is the current active lease
163
+ if (this.activeLease != lease) {
164
+ return;
165
+ }
166
+ this.activeLease = null;
167
+ if (this.closed) {
168
+ return;
169
+ }
170
+ if (this.connection) {
171
+ this.notifyConnectionAvailable();
172
+ }
173
+ else {
174
+ // The leased connection was destroyed. Reconnect now in case a
175
+ // request was queued while this slot still held the lease.
176
+ this.poke().catch((error) => framework.logger.error('Failed to restore Postgres connection', error));
177
+ }
113
178
  }
114
179
  };
115
180
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectionSlot.js","sourceRoot":"","sources":["../../../src/db/connection/ConnectionSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAC/D,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AAuBrD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,MAAM,OAAO,cAAe,SAAQ,SAAS,CAAC,YAAoC;IAS1D;IARtB,WAAW,CAAU;IACrB,QAAQ,CAAU;IAElB,MAAM,CAAU;IAEN,UAAU,CAA6B;IACvC,iBAAiB,CAAsC;IAEjE,YAAsB,OAA8B;QAClD,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAAuB;QAElD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAES,KAAK,CAAC,OAAO;QACrB,IAAI,CAAC,iBAAiB,GAAG,MAAM,CA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PostgresConnection<DatabaseC
34
34
  protected connections: ConnectionSlot[];
35
35
  protected initialized: Promise<void>;
36
36
  protected queue: PromiseWithResolvers<ConnectionLease>[];
37
+ /** Latest exhausted connection attempt for each slot in the current attempt round. */
38
+ protected failedConnectionSlots: Map<ConnectionSlot, unknown>;
37
39
  constructor(options: DatabaseClientOptions);
38
40
  protected get baseConnection(): pgwire.PgClient;
39
41
  protected get schemaStatement(): {
@@ -54,11 +56,12 @@ export declare class DatabaseClient extends AbstractPostgresConnection<DatabaseC
54
56
  protected pokeSlots(): void;
55
57
  protected leaseConnectionSlot(): ConnectionLease | null;
56
58
  protected processConnectionQueue(): void;
59
+ protected handleConnectionAvailable(slot: ConnectionSlot): void;
57
60
  /**
58
- * Reports connection errors which might occur from bad configuration or
59
- * a server which is no longer available.
60
- * This fails all pending requests.
61
+ * Lease requests wait in one shared queue and are not assigned to a slot
62
+ * until that slot becomes available. A failure from one slot therefore
63
+ * cannot fail a particular request: another slot may still serve it.
61
64
  */
62
- protected handleConnectionError(exception: any): void;
65
+ protected handleConnectionError(slot: ConnectionSlot, exception: any): void;
63
66
  [Symbol.asyncDispose](): Promise<void>;
64
67
  }
@@ -19,6 +19,8 @@ export class DatabaseClient extends AbstractPostgresConnection {
19
19
  connections;
20
20
  initialized;
21
21
  queue;
22
+ /** Latest exhausted connection attempt for each slot in the current attempt round. */
23
+ failedConnectionSlots;
22
24
  constructor(options) {
23
25
  super();
24
26
  this.options = options;
@@ -27,6 +29,7 @@ export class DatabaseClient extends AbstractPostgresConnection {
27
29
  maxSize: options.config.max_pool_size,
28
30
  applicationName: options.applicationName
29
31
  });
32
+ this.failedConnectionSlots = new Map();
30
33
  this.connections = Array.from({ length: TRANSACTION_CONNECTION_COUNT }, (v, index) => {
31
34
  // Only listen to notifications on a single (the first) connection
32
35
  const notificationChannels = index == 0 ? options.notificationChannels : [];
@@ -36,8 +39,8 @@ export class DatabaseClient extends AbstractPostgresConnection {
36
39
  applicationName: options.applicationName
37
40
  });
38
41
  slot.registerListener({
39
- connectionAvailable: () => this.processConnectionQueue(),
40
- connectionError: (ex) => this.handleConnectionError(ex),
42
+ connectionAvailable: () => this.handleConnectionAvailable(slot),
43
+ connectionError: (ex) => this.handleConnectionError(slot, ex),
41
44
  connectionCreated: (connection) => this.iterateAsyncListeners(async (l) => l.connectionCreated?.(connection))
42
45
  });
43
46
  return slot;
@@ -59,14 +62,12 @@ export class DatabaseClient extends AbstractPostgresConnection {
59
62
  }
60
63
  registerListener(listener) {
61
64
  let disposeNotification = null;
62
- if ('notification' in listener) {
65
+ if ('notificationEvent' in listener) {
63
66
  // Pass this on to the first connection slot
64
67
  // It will only actively listen on the connection once a listener has been registered
65
- disposeNotification = this.connections[0].registerListener({
66
- notification: listener.notification
67
- });
68
+ disposeNotification = this.connections[0].registerListener({ notificationEvent: listener.notificationEvent });
68
69
  this.pokeSlots();
69
- delete listener['notification'];
70
+ delete listener.notificationEvent;
70
71
  }
71
72
  const superDispose = super.registerListener(listener);
72
73
  return () => {
@@ -161,12 +162,21 @@ export class DatabaseClient extends AbstractPostgresConnection {
161
162
  // Queue the operation
162
163
  const deferred = Promise.withResolvers();
163
164
  this.queue.push(deferred);
165
+ // Try already-connected slots first. poke() only creates missing
166
+ // connections and does not emit another availability event for an existing
167
+ // connection, so skipping this could leave the request queued indefinitely.
168
+ this.processConnectionQueue();
164
169
  this.pokeSlots();
165
170
  return deferred.promise;
166
171
  }
167
172
  pokeSlots() {
168
- // Poke the slots to check if they are alive
173
+ // Ensure the slots have connections and notify any queued requests.
169
174
  for (const slot of this.connections) {
175
+ if (!slot.isConnected && !slot.isPoking) {
176
+ // This slot is starting a fresh attempt, so a failure from an earlier
177
+ // attempt must not count against the current request.
178
+ this.failedConnectionSlots.delete(slot);
179
+ }
170
180
  // No need to await this. Errors are reported asynchronously
171
181
  slot.poke();
172
182
  }
@@ -197,12 +207,24 @@ export class DatabaseClient extends AbstractPostgresConnection {
197
207
  }
198
208
  }
199
209
  }
210
+ handleConnectionAvailable(slot) {
211
+ // This slot recovered, so its earlier failure must no longer contribute to
212
+ // deciding whether the shared lease queue is unreachable.
213
+ this.failedConnectionSlots.delete(slot);
214
+ this.processConnectionQueue();
215
+ }
200
216
  /**
201
- * Reports connection errors which might occur from bad configuration or
202
- * a server which is no longer available.
203
- * This fails all pending requests.
217
+ * Lease requests wait in one shared queue and are not assigned to a slot
218
+ * until that slot becomes available. A failure from one slot therefore
219
+ * cannot fail a particular request: another slot may still serve it.
204
220
  */
205
- handleConnectionError(exception) {
221
+ handleConnectionError(slot, exception) {
222
+ this.failedConnectionSlots.set(slot, exception);
223
+ if (this.failedConnectionSlots.size < this.connections.length) {
224
+ return;
225
+ }
226
+ // Every slot has exhausted its attempts, so no slot can currently make
227
+ // progress on the shared queue.
206
228
  for (const q of this.queue) {
207
229
  q.reject(exception);
208
230
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseClient.js","sourceRoot":"","sources":["../../../src/db/connection/DatabaseClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,KAAK,MAAM,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAmB,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAoB3D,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,0BAAkD;IAY9D;IAXtB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IAEpB,MAAM,CAAU;IAEhB,IAAI,CAAkB;IAEZ,WAAW,CAAmB;IAE9B,WAAW,CAAgB;IAC3B,KAAK,CAA0C;IAEzD,YAAsB,OAA8B;QAClD,KAAK,E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AC,OAAO,CAAC,EAAE,CAAC;YACX,8DAA8D;YAC9D,qFAAqF;QACvF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAEtB,6BAA6B;QAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@powersync/lib-service-postgres",
3
3
  "repository": "https://github.com/powersync-ja/powersync-service",
4
- "version": "0.5.1",
4
+ "version": "0.5.3",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -15,9 +15,9 @@
15
15
  "ts-codec": "^1.3.0",
16
16
  "uri-js": "^4.4.1",
17
17
  "uuid": "^14.0.0",
18
- "@powersync/lib-services-framework": "0.9.7",
19
- "@powersync/service-jpgwire": "0.21.20",
20
- "@powersync/service-types": "0.16.1"
18
+ "@powersync/lib-services-framework": "0.10.0",
19
+ "@powersync/service-jpgwire": "0.21.22",
20
+ "@powersync/service-types": "0.17.0"
21
21
  },
22
22
  "devDependencies": {},
23
23
  "scripts": {