Skip to content

Conversation

@itslenny
Copy link
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

There is no log entry created for connections that don't trigger a request.

  • connections that timeout (at the node:http level)
  • connections that are aborted before a full http request is received
  • connections that send data that can't be parsed

What is the new behavior?

Create a log entry for all connections that don't result in a request event

Example logs

Disconnect before data sent

# close connection after 1 second
timeout 1 tail -f /dev/null | nc localhost 5000
Screenshot 2025-10-17 at 2 30 03 PM

Node http connection timeout

# leave connection open triggers node:http timeout
tail -f /dev/null | nc localhost 5000
Screenshot 2025-10-17 at 2 33 01 PM

Send unparsable data

printf "saldfijasdflijasdflisadfsldif" | nc localhost 5000
Screenshot 2025-10-17 at 2 30 17 PM

Send incomplete data

printf "POST /object/mybucket/file.txt HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: MyClient/1.0\r\nx-forwarded-host: bjhaohmqunupljrqypxz.local.com\r\nAuthorization: Bearer xxx\r\n" | nc localhost 5000
Screenshot 2025-10-17 at 2 30 38 PM

Send complete headers with no payload

# Triggers ABORTED REQ (existing behavior)
printf "POST /object/mybucket/file.txt HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: MyClient/1.0\r\nx-forwarded-host: bjhaohmqunupljrqypxz.local.com\r\nAuthorization: Bearer xxx\r\n\r\n" | nc localhost 5000
Screenshot 2025-10-17 at 2 30 57 PM

@coveralls
Copy link

Pull Request Test Coverage Report for Build 18602068662

Details

  • 76 of 170 (44.71%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 76.185%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/http/plugins/log-request.ts 52 89 58.43%
src/internal/http/partial-http-parser.ts 23 80 28.75%
Totals Coverage Status
Change from base Build 18352064985: -0.2%
Covered Lines: 21251
Relevant Lines: 27665

💛 - Coveralls

async (fastify) => {
// Watch for connections that timeout or disconnect before complete HTTP headers are received
// Log if socket closes before request is triggered
fastify.server.on('connection', (socket) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would need to remove these event handlers at the end of the request otherwise we will create memory leaks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need to consider that we use keep-alive so connections might be reused hence the listeners would be removed in the current implementation

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.

3 participants