pgserve 1.0.5 → 1.0.6

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.
@@ -179,10 +179,13 @@ async function main() {
179
179
  const options = parseArgs();
180
180
  const memoryMode = !options.dataDir;
181
181
 
182
- console.log(`
182
+ // Only print header if not a cluster worker (workers get PGSERVE_WORKER env)
183
+ if (!process.env.PGSERVE_WORKER) {
184
+ console.log(`
183
185
  pgserve - Embedded PostgreSQL Server
184
186
  =====================================
185
187
  `);
188
+ }
186
189
 
187
190
  try {
188
191
  let server;
@@ -254,16 +257,18 @@ Press Ctrl+C to stop
254
257
  `);
255
258
  }
256
259
 
257
- // Graceful shutdown
258
- const shutdown = async () => {
259
- console.log('\nShutting down...');
260
- await server.stop();
261
- console.log('Server stopped.');
262
- process.exit(0);
263
- };
260
+ // Graceful shutdown (only for primary/single-process, workers handle via IPC)
261
+ if (!process.env.PGSERVE_WORKER) {
262
+ const shutdown = async () => {
263
+ console.log('\nShutting down...');
264
+ await server.stop();
265
+ console.log('Server stopped.');
266
+ process.exit(0);
267
+ };
264
268
 
265
- process.on('SIGINT', shutdown);
266
- process.on('SIGTERM', shutdown);
269
+ process.on('SIGINT', shutdown);
270
+ process.on('SIGTERM', shutdown);
271
+ }
267
272
 
268
273
  // Keep process alive
269
274
  await new Promise(() => {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgserve",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Embedded PostgreSQL server with true concurrent connections - zero config, auto-provision databases",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/cluster.js CHANGED
@@ -74,6 +74,8 @@ class ClusterRouter extends EventEmitter {
74
74
  }
75
75
 
76
76
  this.adminClient = new pg.Client(connectionConfig);
77
+ // Suppress errors during shutdown (PostgreSQL terminating connections)
78
+ this.adminClient.on('error', () => {});
77
79
  await this.adminClient.connect();
78
80
  }
79
81
 
@@ -178,7 +180,11 @@ class ClusterRouter extends EventEmitter {
178
180
  this.connections.clear();
179
181
 
180
182
  if (this.adminClient) {
181
- await this.adminClient.end();
183
+ try {
184
+ await this.adminClient.end();
185
+ } catch {
186
+ // Ignore - connection may already be terminated
187
+ }
182
188
  }
183
189
 
184
190
  if (this.server) {
@@ -231,11 +237,18 @@ export async function startClusterServer(options = {}) {
231
237
  workers.set(worker.id, worker);
232
238
  }
233
239
 
234
- // Restart dead workers
240
+ // Track shutdown state to prevent worker restart during shutdown
241
+ let shuttingDown = false;
242
+
243
+ // Restart dead workers (unless shutting down)
235
244
  cluster.on('exit', (worker, code, signal) => {
236
- console.log(`[pgserve] Worker ${worker.id} died (${signal || code}), restarting...`);
237
245
  workers.delete(worker.id);
238
246
 
247
+ if (shuttingDown) {
248
+ return; // Don't restart during shutdown
249
+ }
250
+
251
+ console.log(`[pgserve] Worker ${worker.id} died (${signal || code}), restarting...`);
239
252
  const newWorker = cluster.fork({
240
253
  PGSERVE_WORKER: 'true',
241
254
  PGSERVE_PORT: String(port),
@@ -270,6 +283,7 @@ export async function startClusterServer(options = {}) {
270
283
  pgSocketPath,
271
284
  stop: async () => {
272
285
  console.log('[pgserve] Stopping cluster...');
286
+ shuttingDown = true; // Prevent worker restart during shutdown
273
287
  for (const worker of workers.values()) {
274
288
  worker.send({ type: 'shutdown' });
275
289
  }