Conversation
…for proxy chain SSE connections through Cloudflare → Envoy → Node.js are killed after ~125s of idle time. This adds two fixes: 1. SSE heartbeat: sends `: ping\n\n` comments every 30s (configurable via GITLAB_SSE_HEARTBEAT_MS) to keep connections alive through proxies. Applied to both legacy /sse and modern StreamableHTTP GET endpoints. 2. HTTP server timeouts: configures keepAliveTimeout (620s), headersTimeout (625s), and timeout (0) to prevent Node.js from closing connections before upstream proxies do. Configurable via GITLAB_HTTP_KEEPALIVE_TIMEOUT_MS. Closes #139
Test Coverage ReportOverall Coverage: 93.18%
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical production issue where SSE connections through proxy chains (Cloudflare → Envoy → Node.js) are killed after approximately 125 seconds of idle time. The fix implements two complementary solutions: SSE heartbeat keepalives and proper HTTP server timeout configuration.
Changes:
- Added configurable SSE heartbeat mechanism sending
: ping\n\ncomments every 30 seconds to keep connections alive through proxies - Configured HTTP server timeouts (keepAliveTimeout=620s, headersTimeout=625s, timeout=0) to prevent Node.js from closing connections before upstream proxies
- Applied heartbeat to both legacy
/sseendpoint and modern StreamableHTTP GET endpoints with proper cleanup on connection close
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/config.ts | Added SSE_HEARTBEAT_MS and HTTP_KEEPALIVE_TIMEOUT_MS configuration with environment variable parsing and validation |
| src/server.ts | Implemented startSseHeartbeat() helper, configureServerTimeouts(), integrated heartbeat into both SSE endpoints, and switched to http.createServer() for timeout control |
| tests/unit/server.test.ts | Added 10 comprehensive unit tests covering heartbeat lifecycle, ping delivery, cleanup, and HTTP timeout configuration |
|
🎉 This PR is included in version 6.31.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
: ping\n\ncomments every 30s) to keep connections alive through Cloudflare/Envoy proxy chains that kill idle SSE streams after ~125skeepAliveTimeout=620s,headersTimeout=625s,timeout=0) to prevent Node.js from closing connections before upstream proxiesGITLAB_SSE_HEARTBEAT_MSandGITLAB_HTTP_KEEPALIVE_TIMEOUT_MSenvironment variables/sseand modern StreamableHTTP GET endpointsChanges
src/config.ts— AddSSE_HEARTBEAT_MSandHTTP_KEEPALIVE_TIMEOUT_MSconfig with env var parsingsrc/server.ts— AddstartSseHeartbeat()helper,configureServerTimeouts(), integrate into both SSE endpoints, usehttp.createServer()for proper timeout controltests/unit/server.test.ts— 10 new tests covering heartbeat start/stop/ping, GET SSE streams, POST non-heartbeat, HTTP timeout configurationTest plan
DR(Downstream Reset) flags no longer appear at ~125sCloses #139