I’m testing out some logic that requires a kept-alive connection. If I spin up a trivial server (using connect
) it works as expected – I receive N requests over a single connection.
However, when I try using the exact same client code to call a simple handler embedded in a more complex application (that still uses the same version of connect and node, running on the same OS) I get N requests over N connections.
I’ve already checked the obvious:
- the Connection: keep-alive header is being received, and set in the response
- the timeout (all of them) is reasonable and larger than the request, response or processing time
I dug into this quite deep and found the “cause” is something (on the server) calling onStreamRead
with nread=UV_EOF
which then closed the connection – though interestingly the client didn’t emit a close event until the timeout was hit.
In the simple server where it works, I only receive the UV_EOF
when I explicitly close the client (as expected) – in the complex embedded case where it doesn’t work, I receive that “immediately” (though not synchronously) after ending the HTTP response. The “something” is in the C code of the TCP handler and not something I can debug. My understanding is that it will be invoked in this way when something tries to read a closed stream. More accurately, that callback should be invoked whenever anything reads from the stream, and despite receiving and processing a small payload, it never gets called except in the UV_EOF
condition.
I’ve looked throughout my app code, and through as much of the (significant) library code I can see, there’s nothing I can find that I can think would cause this.
Is there something obvious I’ve missed?
- a flag in node/connect that would kill connections
- some common handler/middleware that attempts to read a connection past its end
What approaches are there to further debug this?
- I’ve already tried calling
debug
on all the relevant (readStart, readStop, shutdown, close, asyncReset, setKeepAlive) methods of the TCP handle – they all get triggered after theUV_EOF
has been emitted.