test: Fix socket hang up in node-fetch 3.3.2 fails tests#10443
test: Fix socket hang up in node-fetch 3.3.2 fails tests#10443mtrezza merged 1 commit intoparse-community:alphafrom
Conversation
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
📝 WalkthroughWalkthroughThree test specification files were updated to inject custom HTTP agent configuration into their local Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
spec/vulnerabilities.spec.js (1)
3-7: Enforce the no-keepalive agent and avoid creating a new Agent per call.
Line 6currently letsoptions.agentoverride your no-keepalive setting (...optionsis last), and it allocates a freshhttp.Agenton every request. Reuse one agent and place it last in the merge so the intent is guaranteed.♻️ Proposed refactor
+const noKeepAliveAgent = new http.Agent({ keepAlive: false }); const fetch = (...args) => - import('node-fetch').then(({ default: fetch }) => { + import('node-fetch').then(({ default: nodeFetch }) => { const [url, options = {}] = args; - return fetch(url, { agent: new http.Agent({ keepAlive: false }), ...options }); + return nodeFetch(url, { ...options, agent: noKeepAliveAgent }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/vulnerabilities.spec.js` around lines 3 - 7, The custom fetch wrapper creates a new http.Agent on every call and allows options.agent to override the no-keepalive intent; instead, create and reuse a single Agent instance (e.g., const noKeepAliveAgent = new http.Agent({ keepAlive: false })) and when merging arguments ensure this agent is applied last so it cannot be overridden (use mergedOptions = { ...options, agent: noKeepAliveAgent } or equivalent) in the fetch implementation (identify the fetch wrapper, the http.Agent creation, and options.agent usage to update).spec/GraphQLQueryComplexity.spec.js (1)
5-9: Same fetch helper hardening: prevent agent override and reuse one Agent instance.
Line 8has the same override/order issue and per-requestAgentallocation. Apply the same pattern here for consistency and deterministic no-keepalive behavior.♻️ Proposed refactor
+const noKeepAliveAgent = new http.Agent({ keepAlive: false }); const fetch = (...args) => - import('node-fetch').then(({ default: fetch }) => { + import('node-fetch').then(({ default: nodeFetch }) => { const [url, options = {}] = args; - return fetch(url, { agent: new http.Agent({ keepAlive: false }), ...options }); + return nodeFetch(url, { ...options, agent: noKeepAliveAgent }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@spec/GraphQLQueryComplexity.spec.js` around lines 5 - 9, The fetch helper currently creates a new http.Agent per call and allows callers to override the agent; change the implementation of the fetch helper (the fetch const) so it creates a single shared agent instance (e.g., const sharedAgent = new http.Agent({ keepAlive: false }) declared once outside the returned function) and when merging options ensure the agent cannot be overridden by incoming options (apply the incoming options after setting agent but omit any incoming agent key or explicitly set agent: sharedAgent), preserving deterministic no-keepalive behavior and avoiding per-request Agent allocation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@spec/ParseGraphQLServer.spec.js`:
- Around line 4-8: The inline fetch shim in the spec allows options.agent to
override the forced non-keepalive agent; update the merge so the created Agent
with keepAlive: false cannot be replaced (e.g., apply options first and then set
agent, or explicitly set agent = options.agent ?? new http.Agent({ keepAlive:
false }) before calling fetch). Modify the fetch helper in
ParseGraphQLServer.spec.js (the top-level fetch arrow function) so the final
options passed to the real fetch always have an agent with keepAlive: false.
---
Nitpick comments:
In `@spec/GraphQLQueryComplexity.spec.js`:
- Around line 5-9: The fetch helper currently creates a new http.Agent per call
and allows callers to override the agent; change the implementation of the fetch
helper (the fetch const) so it creates a single shared agent instance (e.g.,
const sharedAgent = new http.Agent({ keepAlive: false }) declared once outside
the returned function) and when merging options ensure the agent cannot be
overridden by incoming options (apply the incoming options after setting agent
but omit any incoming agent key or explicitly set agent: sharedAgent),
preserving deterministic no-keepalive behavior and avoiding per-request Agent
allocation.
In `@spec/vulnerabilities.spec.js`:
- Around line 3-7: The custom fetch wrapper creates a new http.Agent on every
call and allows options.agent to override the no-keepalive intent; instead,
create and reuse a single Agent instance (e.g., const noKeepAliveAgent = new
http.Agent({ keepAlive: false })) and when merging arguments ensure this agent
is applied last so it cannot be overridden (use mergedOptions = { ...options,
agent: noKeepAliveAgent } or equivalent) in the fetch implementation (identify
the fetch wrapper, the http.Agent creation, and options.agent usage to update).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 39cab0b1-b102-4261-b57e-11cfda3c3b2e
📒 Files selected for processing (3)
spec/GraphQLQueryComplexity.spec.jsspec/ParseGraphQLServer.spec.jsspec/vulnerabilities.spec.js
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #10443 +/- ##
==========================================
+ Coverage 92.09% 92.51% +0.41%
==========================================
Files 192 192
Lines 16792 16792
Branches 234 234
==========================================
+ Hits 15465 15535 +70
+ Misses 1300 1234 -66
+ Partials 27 23 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
🎉 This change has been released in version 9.9.0-alpha.1 |
Pull Request
Issue
After bumping
node-fetchfrom 3.2.10 to 3.3.2, GraphQL tests intermittently fail withsocket hang uperrors, for example:Approach
node-fetch 3.2.10 automatically set
Connection: closeon every request. Version 3.3.2 removed that header (node-fetch/node-fetch#1736), deferring to Node.js defaults. On Node.js 19+, the default HTTP agent haskeepAlive: true, so TCP connections persist in the agent's pool. When tests tear down and recreate the HTTP server on the same port between specs, stale pooled sockets get reused against the dead server, causingsocket hang up.The fix passes
new http.Agent({ keepAlive: false })in the lazy fetch wrapper used by the three affected test files, restoring close-after-response behavior.Tasks
Add changes to documentation (guides, repository pages, code comments)Add security checkAdd new Parse Error codes to Parse JS SDKSummary by CodeRabbit