Skip to content

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

Open
Yanhu007 wants to merge 1 commit intoelectric-sql:mainfrom
Yanhu007:fix/socket-server-start-error-propagation
Open

fix(pglite-socket): propagate server startup errors from start()#972
Yanhu007 wants to merge 1 commit intoelectric-sql:mainfrom
Yanhu007:fix/socket-server-start-error-propagation

Conversation

@Yanhu007
Copy link
Copy Markdown

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()
})

The error handler in start() checks `if (!this.active)` before
calling reject(), but this.active is set to true before the
server.listen() call. When listen fails (e.g. EACCES, EADDRINUSE),
the error is logged and emitted but reject() is never called,
causing the start() Promise to hang forever.

Replace the this.active check with a local `listening` flag that
is only set to true inside the listen callback. This ensures
startup errors always reject the Promise.

Fixes electric-sql#964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: PGLiteSocketServer swallows errors on startup

1 participant