pglite icon indicating copy to clipboard operation
pglite copied to clipboard

fix(pglite-socket): propagate server startup errors from start()

Open Yanhu007 opened this issue 7 months ago • 1 comments

Summary

Fixes #964

PGLiteSocketServer.start() hangs forever when the underlying server fails to start (e.g. EACCES, EADDRINUSE). The error is logged and emitted via CustomEvent, but the Promise never rejects.

Root Cause

The error handler checks if (!this.active) before calling reject(), but this.active is set to true at line 601 — before server.listen() is called. When listen emits an error, !this.active is false, so reject() is never reached.

Fix

Replace the this.active check with a local listening flag that is only set to true inside the listen callback:

let listening = false

this.server.on('error', (err) => {
  // ...
  if (!listening) {
    reject(err)  // Always rejects for startup errors
  }
})

this.server.listen(this.path, () => {
  listening = true  // Only set after successful listen
  resolve()
})

Yanhu007 avatar Apr 12 '26 07:04 Yanhu007

@Yanhu007 Thank you for this! Please run pnpm changeset and choose a patch level change for pglite-socket.

tdrz avatar May 06 '26 12:05 tdrz