[statsig-node] Fix EPIPE errors with proper HTTP agent connection pooling and timeouts #29
+71
−25
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.
Fix EPIPE Errors with Proper HTTP Agent Connection Pooling and Timeouts
Problem
The Node.js SDK was experiencing EPIPE (broken pipe / socket connection issues) errors for us when making HTTP requests. These errors occurred due to:
https-proxy-agentdidn't properly handle connection reusefreeSocketTimeoutwas configured, causing stale connections to be reused after the server had closed themSolution
This PR replaces
https-proxy-agentwithagentkeepaliveandhpagentto implement proper HTTP agent connection pooling with comprehensive timeout configuration:Key Changes
Replaced dependencies:
https-proxy-agent@^7.0.6agentkeepalive@^4.5.0andhpagent@^1.2.0Implemented shared HTTP/HTTPS agents with proper timeout configuration:
timeout: 30000- Request timeout matching SDK defaultsfreeSocketTimeout: 15000- Prevents EPIPE errors from stale connectionskeepAlive: trueandkeepAliveMsecs: 1000- Enables connection reuseEnhanced proxy support:
createProxyAgent→createProxyAgentsto return both HTTP and HTTPS agentsgetAgenthelper function to select the appropriate agent based on URL protocolTechnical Details
agentkeepalive: ProvidesfreeSocketTimeoutsupport across all Node.js versions, which is critical for preventing EPIPE errors when connections are reused after being idlehpagent: Supports all standard agent options (includingkeepAliveandfreeSocketTimeout) for proxy scenarios, ensuring consistent behavior whether using a proxy or direct connectionsBenefits
Testing
Files Changed
statsig-node/package.json- Updated dependenciesstatsig-node/src/lib/index.ts- Core HTTP agent implementationstatsig-node/pnpm-lock.yaml- Lock file updates