Skip to content
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

test: Add test for FIN mishandling in http agent #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dhedey
Copy link
Owner

@dhedey dhedey commented Jan 21, 2024

Refs: nodejs#47130


This is an example test which fails with socket hang up when a socket is re-used. It's probably not a 100% guaranteed repo, but it seems pretty high %age failure (> 95%) to me.

This code is purposefully messy, and is NOT intended for merging upstream. It's instead intended as a reproduction of the claimed issue, and as a tool to be able to understand the problem.

An example error from the test is below.

I believe too much time is allowed to pass between the socket receiving the FIN and the http agent removing the socket from its pool of sockets the agent can route to. This results in the agent re-using the socket in the meantime, where-upon the agent realises and returns an error with socket hang up (it appears this happens in the agent before the request is even sent on the socket).

❯ tools/test.py test/parallel/test-http-agent-fin-handling.js          
=== release test-http-agent-fin-handling ===                   
Path: parallel/test-http-agent-fin-handling
CLIENT_PORT_RECEIVED_FROM_SERVER: 64952
SERVER_SOCKET_OPEN: 1
SERVER_SOCKET_OPEN: 2
SERVER_SEND_FIN: 1
CLIENT_FULL_RESPONSE_RECEIVED: for Request 2
SERVER_SEND_FIN: 2
CLIENT_FULL_RESPONSE_RECEIVED: for Request 1
CLIENT_SOCKET_REUSED: Socket from Request 2 reused for Request 1.1
node:assert:173
  throw err;
  ^

AssertionError [ERR_ASSERTION]: Request error at Request 1.1: Error: socket hang up (e.code: ECONNRESET)
    at ClientRequest.<anonymous> (/****/test/parallel/test-http-agent-fin-handling.js:109:12)
    at ClientRequest.emit (node:events:519:28)
    at Socket.socketCloseListener (node:_http_client:465:11)
    at Socket.emit (node:events:531:35)
    at TCP.<anonymous> (node:net:337:12) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: undefined,
  operator: 'fail'
}

Node.js v22.0.0-pre
Command: out/Release/node /****/test/parallel/test-http-agent-fin-handling.js


[00:00|% 100|+   0|-   1]: Done                                

Failed tests:
out/Release/node /****/test/parallel/test-http-agent-fin-handling.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant