Skip to content

SIGINT during in-flight request causes abrupt termination in Elysia (pending handlers are aborted) #1214

@el-tumakov

Description

@el-tumakov

What version of Elysia is running?

1.3.1

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

  1. Create a file index.js with the following content:
import { sleep } from 'bun';
import { Elysia } from 'elysia';

const app = new Elysia()
  .get('/', async () => {
    await sleep(5000);
    return 'Hello World';
  })
  .listen(3000);

console.log('Server is running');

process.on('SIGINT', () => {
  console.log('Received SIGINT. Stopping server...');
  app.stop().then(() => {
    console.log('Server stopped');
    process.exit(0);
  });
});
  1. Run the server.
  2. In another terminal or browser, issue a request to the server:
curl http://localhost:3000
  1. Immediately press Ctrl+C in the server’s terminal to send SIGINT.

What is the expected behavior?

  • On SIGINT, app.stop() should wait for any in-flight handlers (e.g. the 5s sleep) to resolve.
  • After the handler completes, the server should send the response ("Hello World") and then shut down gracefully.

What do you see instead?

  • The server logs Received SIGINT. Stopping server…
  • Process exits instantly.
  • The pending request is aborted; the client never receives "Hello World".

Additional information

This Bun example correctly waits for the 5s delay before sending the response, then exits.

const server = Bun.serve({
  port: 3000,
  async fetch() {
    await sleep(5000);
    return new Response('Hello World');
  },
});

console.log('Server is running');

process.on('SIGINT', () => {
  console.log('Received SIGINT. Stopping server...');
  server.stop().then(() => {
    console.log('Server stopped');
    process.exit(0);
  });
});

Have you try removing the node_modules and bun.lockb and try again yet?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions