-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: should HEAD request keepalive by default #566
Conversation
WalkthroughThe pull request introduces enhancements to the HTTP client's request handling, focusing on connection management and keep-alive behavior. The changes span multiple files, including Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
src/diagnosticsChannel.ts (2)
29-29
: Consider a more precise union type if needed.
This addition of 'boolean' to the dictionary indexing is correct if you require the possibility of a boolean. However, consider whether a narrower type or separate property might be clearer if only certain symbols can be boolean.
51-51
: Document the new 'reset' property in the returned object.
Returning 'reset' in the formatted socket object is useful for diagnostics, but consider adding a brief explanation in comments or the docstring offormatSocket()
clarifying its usage.test/fetch-head-request-should-keepalive.test.ts (2)
30-37
: HEAD request verification.
Sending subsequent HEAD requests is a valid approach to confirm keep-alive. Test logs look good. Potentially consider additional negative testing (e.g., forcing the server to close).
38-71
: Commented-out code.
Many lines of test code are commented out. If you plan to enable them later, consider adding a TODO comment or removing them to stay consistent with the main test logic.test/head-request-should-keepalive.test.ts (2)
7-20
: Test suite metadata.
The test suite references the GitHub issue #565, which is valuable for context. Maintaining this cross-link ensures future maintainers can quickly connect the test coverage to the original problem statement.
50-74
: Expand coverage for HEAD requests under different conditions.
Currently, these HEAD requests appear straightforward. Consider adding an assertion for content-length or verifying that the server truly does not return a body.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/HttpClient.ts
(1 hunks)src/Request.ts
(1 hunks)src/diagnosticsChannel.ts
(2 hunks)src/fetch.ts
(1 hunks)test/diagnostics_channel.test.ts
(9 hunks)test/fetch-head-request-should-keepalive.test.ts
(1 hunks)test/fixtures/server.ts
(2 hunks)test/head-request-should-keepalive.test.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- src/Request.ts
- src/fetch.ts
🔇 Additional comments (13)
src/diagnosticsChannel.ts (2)
32-43
: Validate the symbol assignment logic.
The code identifies a symbol with description 'reset' from the socket, assigns it to kSocketReset, and then breaks out of the loop. Make sure it’s not possible for a legitimate second 'reset' symbol to be skipped. Additionally, handle the case where the symbol is never found.
6-7
: Be cautious when ignoring TypeScript errors.
While these comments suppress TypeScript checks and allow the import to pass, this may mask potential type issues that could arise later.
Would you like a script to search for all places where @ts-ignore is used, to ensure they are still necessary?
✅ Verification successful
Let me analyze the usage of @ts-ignore
in the codebase further to understand if they are necessary.
Let me check the actual location of the symbols file and its content since the import path shows './symbols.js'.
Let me check the content of symbols.ts since we found it earlier.
The @ts-ignore
for symbols import is necessary and justified.
The @ts-ignore
is used here because the code imports ./symbols.js
while the actual file is symbols.ts
. This is a common pattern in TypeScript projects where .js
extensions are used in imports even for TypeScript files, as the compiled output will use .js
extensions. The TypeScript compiler would normally flag this as an error, but in this case, ignoring it is the correct approach since:
- The symbols module is properly typed (exports a collection of Symbols)
- The import is working as expected in the runtime
- The symbols are used extensively throughout the diagnostics channel implementation
- This pattern is consistent with other similar imports in the codebase (seen in fetch.ts and HttpClient.ts)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# This script will list lines containing "@ts-ignore" in .ts files, providing context.
rg -A 3 '@ts-ignore' --glob '*.ts'
Length of output: 2129
Script:
#!/bin/bash
# Check the content of symbols.js to understand why ts-ignore is needed in diagnosticsChannel.ts
cat src/symbols.js
# Check if there are any type definition files for the imports
fd -e d.ts
Length of output: 100
Script:
#!/bin/bash
# Find the symbols file
fd symbols
# Let's also check the actual import in diagnosticsChannel.ts
cat src/diagnosticsChannel.ts
Length of output: 10756
Script:
#!/bin/bash
# Check the content of symbols.ts
cat src/symbols.ts
Length of output: 1129
src/HttpClient.ts (1)
431-431
: Reevaluate defaulting 'reset' to false.
Setting "reset" to false ensures a keep-alive by default, which aligns with the PR “fix: should HEAD request keepalive by default”. However, confirm that all HEAD request scenarios handle the “reset: true” case safely if toggled at runtime.
test/fetch-head-request-should-keepalive.test.ts (3)
1-6
: Tests properly set up environment.
Great job importing the necessary modules and using Vitest for testing. The usage of a custom scheduler is a good approach for asynchronous timing-based tests.
7-21
: Skip directive might hide essential tests.
The entire describe block is marked with “.skip”, so these tests will not run. If intended only for local debugging or incomplete features, clearly document that or remove the skip to ensure coverage.
22-28
: Confirm GET request response.
The test checks for a status of 200 and a “keep-alive” connection, which aligns with the PR objective to maintain keepalive. Ensure the server fixture always reflects the actual HEAD request behavior.
test/head-request-should-keepalive.test.ts (3)
1-6
: Imports and server fixture usage.
This file properly orchestrates the server lifecycle and the HttpClient import. Good practice! No issues found here.
22-49
: Test keep-alive behavior.
This test thoroughly checks that consecutive HEAD requests reuse the same socket (by comparing socket IDs). This effectively verifies the keep-alive behavior.
76-96
: Confirm 'reset = true' logic.
The second test verifies that the connection is closed when reset = true, aligning with the PR objective. Good coverage.
test/fixtures/server.ts (1)
401-401
: LGTM! Addition of urlWithDns property enhances testing capabilities.
The new property provides an IP-based URL which is useful for testing DNS resolution scenarios and connection reuse patterns. The implementation correctly maintains port consistency with the main URL.
test/diagnostics_channel.test.ts (3)
50-50
: LGTM! Added defensive check for handler existence.
This change prevents potential undefined behavior when the handler is not available, improving the robustness of the diagnostic channel implementation.
92-93
: LGTM! Updated comments to reflect new HEAD request behavior.
The comments now accurately document that both HEAD and GET requests utilize keepalive connections, aligning with the PR's objective to fix HEAD request keepalive behavior.
Also applies to: 315-316
106-106
: LGTM! Updated request counting assertions.
The assertions have been properly adjusted to maintain accurate tracking of request counts across both HEAD and GET requests, ensuring proper validation of connection reuse behavior.
Also applies to: 120-120, 137-137, 329-330, 344-345, 362-363
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #566 +/- ##
==========================================
+ Coverage 95.66% 95.70% +0.04%
==========================================
Files 11 11
Lines 1270 1282 +12
Branches 306 309 +3
==========================================
+ Hits 1215 1227 +12
Misses 51 51
Partials 4 4 ☔ View full report in Codecov by Sentry. |
[skip ci] ## [4.6.10](v4.6.9...v4.6.10) (2024-12-19) ### Bug Fixes * should HEAD request keepalive by default ([#566](#566)) ([54c4a2c](54c4a2c))
closes #565
Summary by CodeRabbit
Release Notes
New Features
reset
property for more control over HTTP requests.Bug Fixes
Tests
Documentation
reset
property in request options to clarify its default behavior.Chores