Skip to content

[Bug]: auth activation that fails after joining the host lease leaves the auth_servers row and a heartbeat timer running #979

Closed

Description

@jimhoyd

Severity: low. Found in an adversarial review of #949 (#941).

Runtime revision and environment

origin/main ba9f3204, Node 26.10, macOS.

What happens

In packages/auth/src/auth.ts activation, lease = await joinHostLease(...) runs before betterAuth(options) and seedUsers(...). The catch only runs database?.close(), never lease?.close(). When a later step throws:

  • the auth_servers row stays until the TTL, which blocks another host from joining meanwhile;
  • the lease's heartbeat setInterval keeps firing against the closed connection indefinitely. Its errors are swallowed and the timer is unref'd, so it is a leak in long-lived processes such as MCP and restartable test runs, not a hang.

Store and audit do not have this problem: the store's opener closes on failure, and nothing follows the lease join there.

Minimal reproduction

Activate the auth extension hermetically with a seed that makes seedUsers throw, e.g. two users with the same email:

activation failed as expected: UNIQUE constraint failed: user.email
auth_servers rows after failed activation: [{ host: '<this host>', pid: <pid> }]
heartbeat callbacks fired after the failed activation: 2   (within ~11 s)

(Observed.)

Suggested fix

Call lease?.close() in that catch (before database?.close()), or join the lease as the last step of activation. Add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions