Closed astuyve closed 1 year ago
This change seems to have had a probably unintended side effect: I am using serverless-http with express and the logger pino-http. Starting at serverless-http@3.1.1 I am seeing all request logs getting logged twice. I added a super minimal demo project here to show the issue: https://github.com/zoellner/serverless-http-pino-bug
I want to preface this with the fact that I don't know much about the Node internals patched by this library here, so please do help me correct any misunderstandings as I'm sure there are several.
I ran into an issue in dd-trace where an instance of
http.ServerResponse
emitted onlyfinish
and notclose
. Based on my understanding of the docs, we'd expect to seefinish
andclose
after an instance ofhttp.ServerResponse
has finished and the response written to the network interface.To verify that understanding, I wrote a tiny webserver and confirmed the behavior:
However, while tracking down this issue, I noticed that running this library (with express, specifically) within a lambda function doesn't emit
close
when the response is finished. Rather onlyfinish
is emitted from thehttp.ServerResponse
. This caused Datadog to buffer traces (as our APM telemetry didn't think the response was done), and never flush.I fixed this on our side here, but I wanted to fix this upstream.
If I understand correctly, Node should automatically emit close when the socket receives close, but that doesn't happen here as our socket doesn't ever really
close
.Here's a similar implementation which manually plumbs a socket to a response, where they call
socket.end()
whenresponse#finish
is received; so this is the route I chose here.