Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Silenced a false-positive `MaxListenersExceededWarning` logged on every request proxied through an external rewrite. [#1697](https://github.com/sourcebot-dev/sourcebot/pull/1697)

## [5.1.15] - 2026-09-29

### Added
Expand Down
16 changes: 16 additions & 0 deletions packages/web/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/nextjs';
import type { ServerResponse } from 'node:http';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
Expand All @@ -10,6 +11,21 @@ export async function register() {
}

if (process.env.NEXT_RUNTIME === 'nodejs') {
// Proxied rewrites (`/ingest/*` for PostHog, the `/monitoring` Sentry
// tunnel) legitimately attach 11 `close` listeners to each response: 9
// from Next's rewrite proxy plus 2 from Sentry. That crosses Node's
// default limit of 10 and logs a MaxListenersExceededWarning on every
// such request, even though the listeners are released with the
// response. The request start channel fires before Next handles the
// request, and scoping the raise to responses keeps the warning
// meaningful for every other emitter. This can be removed once Next
// trims its proxy listeners.
// @see: https://github.com/vercel/next.js/issues/97757
const { subscribe } = await import('node:diagnostics_channel');
subscribe('http.server.request.start', (message) => {
(message as { response?: ServerResponse }).response?.setMaxListeners(20);
});

const { startMetricsServer } = await import('./metricsServer');
startMetricsServer();

Expand Down
Loading