Skip to content
Latchkey

Sentry SDK transport flush/close timeout hangs the test process in CI

The Sentry SDK queues events and delivers them asynchronously. If the test process ends while events are pending, Sentry.close() waits for the flush; with an unreachable or slow endpoint it blocks up to the timeout, and the test runner reports the process as hanging.

What this error means

Jest logs "did not exit one second after the test run completed" and --detectOpenHandles points at the Sentry HTTP transport, or a call to await Sentry.close(2000) stalls until its timeout.

node
Jest has detected the following 1 open handle:
  TCPWRAP
    at Sentry HttpTransport (node_modules/@sentry/node/...)

Common causes

Pending events flush on process exit

Captured events sit in the transport buffer; ending the process triggers a flush that waits for delivery or the timeout, keeping the event loop alive.

The endpoint is slow or unreachable in CI

When the DSN host cannot be reached from the runner, each delivery waits out its timeout, extending the flush and delaying exit.

How to fix it

Do not send events in tests

  1. Disable Sentry in the test environment so nothing is queued to flush.
  2. If init runs, use enabled:false or beforeSend returning null.
  3. Then there is no transport handle to keep the process alive.
test/setup.js
Sentry.init({ dsn, enabled: process.env.NODE_ENV !== 'test' });

Flush with a short timeout in teardown

If you must send, flush with a small timeout in afterAll so a dead endpoint cannot stall exit.

test/setup.js
afterAll(async () => {
  await Sentry.close(2000);   // bounded flush, then close transport
});

How to prevent it

  • Disable Sentry in unit tests so no transport starts.
  • Bound any flush with a short timeout in teardown.
  • Do not point the SDK at an unreachable endpoint during tests.

Frequently asked questions

What causes "Sentry.close() flush blocks exit"?
Captured events sit in the transport buffer; ending the process triggers a flush that waits for delivery or the timeout, keeping the event loop alive.
How do I fix Sentry.close() flush blocks exit?
Do not send events in tests

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card