[statsig-node] Fix EPIPE errors with proper HTTP agent connection pooling and timeouts#29
Open
holbrookab-augment wants to merge 1 commit intostatsig-io:mainfrom
Conversation
- Replace https-proxy-agent with agentkeepalive and hpagent - Add proper timeout configuration (timeout: 30000, freeSocketTimeout: 15000) - Implement shared HTTP/HTTPS agents with keep-alive settings - Enhance proxy support with both HTTP and HTTPS agents - Maintain backward compatibility
Author
|
@weihao-statsig not urgent, but I made this PR based on some issues we've had recently. Hope it helps! |
Author
|
@weihao-statsig kind bump |
Contributor
|
Ah sorry I missed this earlier, we are actually planning to kill the network layer for node. |
Author
|
@weihao-statsig sorry, what does this mean? The keepAlive / freeSocketTimeout issues are important to us...by killing the network layer will that help with this? |
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.
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