segmentio / analytics-next

Segment Analytics.js 2.0
https://segment.com/docs/connections/sources/catalog/libraries/website/javascript
MIT License
384 stars 128 forks source link

analytics-node does not close HTTPS connection on closeAndFlush #1052

Closed nferch closed 3 months ago

nferch commented 3 months ago

closeAndFlush() does not close the HTTPS connection to the Segment API:

Leaked resources 0:
[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 2 (tty) (stdio)
  - fd 1 (tty) (stdio)
  - fd 0 (tty)
- Sockets:
  - XX.XX.XX.XX:61342 -> 52.12.47.65:443
silesky commented 3 months ago

@nferch thanks for taking out an issue.

Confirming:

I'd have to think on this / repro. This is a bit of a head scratcher that there are open sockets, because there is no open handles -- and IME, pending fetch requests get reflected as callbacks on the event loop.

Weeeird 😅

silesky commented 3 months ago

@nferch I reprod this -- the socket shows clear, but it might take until the next event loop.

await analytics.closeAndFlush()
setImmediate(() => wtf.dump())

results in no open sockets:

// [WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 2 (tty) (stdio)
  - fd 1 (tty) (stdio)