pglite
pglite copied to clipboard
fix(pglite-socket): propagate server startup errors from start()
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 Thank you for this! Please run pnpm changeset and choose a patch level change for pglite-socket.