Skip to content

Bun crashes with segmentation fault when network closes unexpectedly (Knex + PostgreSQL via Neon) #20104

Open
@acoBOYZ

Description

@acoBOYZ

How can we reproduce the crash?

We’re running a Fastify app under Bun (bun dev) with:
• knex for PostgreSQL
• pg driver
• Neon (serverless PostgreSQL) as the database
• Redis pub/sub
• Graceful shutdown using Promise.race() + timeouts on all services

When the PostgreSQL connection is dropped unexpectedly (e.g. Neon idle timeout or network loss), Bun crashes with a segmentation fault.

Additionally, Bun fails to release the port, leaving it in EADDRINUSE state, making it impossible to restart the server without killing the Bun process manually.

Reproduction steps:
1. Start the app using bun dev
2. Use Neon or simulate dropped DB connection (e.g. by disconnecting network)
3. Wait for socket timeout or close event
4. Bun crashes with a segmentation fault
5. Port stays open → app can’t restart

Relevant log output

Connection Error: Connection ended unexpectedly
Connection Error: Connection ended unexpectedly

panic(main thread): Segmentation fault at address 0x656E69676E652360
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

--- Bun is auto-restarting due to crash [time: 1748695000343] ---

^C^C

❯ bun dev
$ bun --watch ./server.ts
Knex is using: pg (JavaScript)
✅ Loaded typeDefs
✅ Connected to Redis Pub
✅ Connected to Redis Sub

error: Failed to start server. Is port 3003 in use?
 syscall: "listen",
   errno: 0,
    code: "EADDRINUSE"

      at serve (node:_http_server:548:41)

error: script "dev" exited with code 1

Stack Trace (bun.report)

Bun v1.2.15 (df01799) on macos aarch64 [AutoCommand]

Segmentation fault at address 0x656E69676E652360

  • 1 unknown/js code
  • deps.uws.NewSocketHandler
  • deps.uws.NewSocketHandler
  • ssl_wrapped_context_on_close
  • ssl_on_close
  • us_socket_close
  • us_internal_dispatch_ready_poll
  • us_loop_run_bun_tick
  • bun.js.event_loop.EventLoop.autoTickActive
  • bun.js.jsc.OpaqueWrap__anon_30396__struct_235725.callback

Features: transpiler_cache, tsconfig, tsconfig_paths, workers_spawned, process_dlopen, Bun.stderr, Bun.stdin, Bun.stdout, http_server, jsc

Sentry Issue: BUN-KQY

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashAn issue that could cause a crashmacOSAn issue that occurs on macOSruntime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions