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.
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
- Disable Sentry in the test environment so nothing is queued to flush.
- If init runs, use
enabled:falseorbeforeSendreturning null. - Then there is no transport handle to keep the process alive.
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.
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.