-
-
Notifications
You must be signed in to change notification settings - Fork 167
fix(http): server write first #816
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,23 @@ it('passes a non-http socket through to the actual server', async () => { | |
|
|
||
| expect(response).toBe('PONG') | ||
| }) | ||
|
|
||
| it.only('server write first', async () => { | ||
| await using server = await createRawTestServer(() => { | ||
| return new net.Server((connection) => { | ||
| connection.write('PING') | ||
| }) | ||
| }) | ||
|
|
||
| const response = await new Promise<string>((resolve, reject) => { | ||
| const socket = net.connect(server.port, server.hostname) | ||
| socket.on('data', (chunk) => { | ||
| resolve(chunk.toString()) | ||
| socket.destroy() | ||
| }) | ||
| socket.on('error', reject) | ||
| }) | ||
|
|
||
| expect(response).toBe('PING') | ||
|
Comment on lines
+51
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate and inspect the referenced test file and nearby code.
if [ -f "test/modules/http/regressions/http-non-http-socket-passthrough.test.ts" ]; then
echo "== file exists =="
wc -l test/modules/http/regressions/http-non-http-socket-passthrough.test.ts
echo
echo "== relevant test file =="
cat -n test/modules/http/regressions/http-non-http-socket-passthrough.test.ts
else
echo "Referenced file not found"
fd -i 'http-non-http-socket-passthrough.test.ts' .
fi
echo
echo "== related server/passthrough definitions =="
git ls-files | xargs rg -n "non-http|PING|passthrough|http-non-http-socket|connect\\(" test src 2>/dev/null | head -200 || trueRepository: mswjs/interceptors Length of output: 23818 🌐 Web query:
💡 Result: In Node.js, the net.Socket 'data' event does not guarantee the receipt of complete messages [1][2]. Because TCP is a stream-oriented protocol rather than a message-oriented one, there is no inherent concept of message boundaries [2][3]. A single logical message sent by a client can be split into multiple 'data' event chunks, or multiple messages can be merged into a single 'data' event chunk [2][4]. Key characteristics regarding 'data' event chunks include: 1. Arbitrary Chunk Size: The size of the 'data' event chunk is non-deterministic [5]. It depends on factors such as network conditions, kernel buffer availability, and the underlying stream's buffering behavior [5][2]. 2. Streaming Nature: When a net.Socket is in flowing mode, it emits 'data' events as soon as data arrives and is read from the kernel [1][5]. You should not assume that a 'data' event payload represents a full logical unit of data [4]. 3. Manual Boundary Handling: Because the network layer does not enforce boundaries, application-level code must implement its own mechanisms to delineate messages [2][3]. Common strategies include: - Length-prefixing: Sending the size of the message as a header before the actual message body [4]. - Delimiters: Using specific characters (e.g., newline \n or other markers) to signal the end of a message [3]. - Buffering: Accumulating received chunks into a buffer and parsing that buffer for complete messages whenever new data arrives [4][3]. If you need better control over how data is read or processed, you can consider using the 'readable' event and the readable.read method, which allow you to manually consume data from the stream's internal buffer instead of relying on the automatic 'data' event flow [6][7]. Citations:
Accumulate TCP chunks before asserting.
🤖 Prompt for AI Agents |
||
| }) | ||
|
|
||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: mswjs/interceptors
Length of output: 2411
Remove
it.onlybefore merging.This focuses Vitest on the new test and skips the other regression tests, which can let failures elsewhere go unnoticed.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents