Skip to content

fix(auth): prevent ERR_SERVER_NOT_RUNNING on magic-link login; harden stopServer#474

Merged
facundo-herodevs merged 1 commit intomainfrom
fr/fix-stop-server
Feb 12, 2026
Merged

fix(auth): prevent ERR_SERVER_NOT_RUNNING on magic-link login; harden stopServer#474
facundo-herodevs merged 1 commit intomainfrom
fr/fix-stop-server

Conversation

@facundo-herodevs
Copy link
Member

Closes https://github.com/neverendingsupport/data-and-integrations/issues/549

Summary

This PR fixes a local CLI auth regression where auth login could throw:

Error [ERR_SERVER_NOT_RUNNING]: Server is not running.

even though authentication completed successfully (most visible in magic-link flows).

Root Cause

The OAuth callback server shutdown (server.close) was not resilient to re-entrant/racing shutdown paths:

  • callback success path triggered shutdown
  • error path could also trigger shutdown shortly after

When close() was called on an already-closed server, Node returned ERR_SERVER_NOT_RUNNING.
Because shutdown was not fully guarded, this surfaced as an exception during CLI login.

Changes

  • Added stopServerPromise to deduplicate concurrent shutdown attempts.
  • Refactored stopServer() to be idempotent:
    • capture server reference once
    • clear this.server early
    • return existing in-flight shutdown promise when present
  • Treated ERR_SERVER_NOT_RUNNING as benign during cleanup.
  • Kept user-facing warning generic (Failed to stop local OAuth callback server.) and moved detailed error info to debug logs.
  • Updated non-awaited shutdown calls to explicit fire-and-forget (void this.stopServer()) where applicable.

Why This Approach

  • Prevents false-negative CLI failures during successful auth flows.
  • Makes shutdown logic deterministic and safe under event races.
  • Keeps CLI output clean for users while preserving debuggability for maintainers.

@facundo-herodevs facundo-herodevs requested a review from a team as a code owner February 9, 2026 18:56
@facundo-herodevs facundo-herodevs merged commit 94039e6 into main Feb 12, 2026
12 checks passed
@facundo-herodevs facundo-herodevs deleted the fr/fix-stop-server branch February 12, 2026 15:02
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.

4 participants