Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Sockets leak #201

Closed
twoeths opened this issue Aug 30, 2022 · 2 comments · Fixed by #204
Closed

Sockets leak #201

twoeths opened this issue Aug 30, 2022 · 2 comments · Fixed by #204
Labels

Comments

@twoeths
Copy link
Contributor

twoeths commented Aug 30, 2022

Description

  • lodestar is trying @libp2p/tcp 3.0.3 and notice that sockets are retained in process._getActiveHandles(), in the last 7 days:

Screen Shot 2022-08-30 at 11 28 22

  • The debugger shows that most of these sockets are inbound and they are not destroyed

Screen Shot 2022-08-30 at 11 32 40

achingbrain added a commit that referenced this issue Aug 31, 2022
We call `.end` on a socket and wait for the `close` event, but calling `.end` only closes the writable end of the socket.

To close both ends we either need to wait for the remote to close their writable end or we need to `.destroy` our socket.  If we call `.destroy` all data is lost and no more I/O occurs.

The change here is to call `.end` then check to see if we have any outgoing writes, if we do, wait for the `drain` event which means the outgoing data has been sent, then call `.destroy`, otherwise call `.destroy` immediately.

At the same time use a timer to call `.destroy` if the `drain` event never arrives.

It also set up the `timeout` event for the socket to allow closing the socket after a period of inactivity.

Three new constructor options are added to control the behvaiour:

- `inboundSocketInactivityTimeout` the socket will be closed after this many ms of not sending/recieving data (default 30s)
- `outboundSocketInactivityTimeout` the socket will be closed after this many ms of not sending/recieving data (default 30s)
- `socketCloseTimeout` how long to wait for the `drain` event (default 2s)

Fixes #201
github-actions bot pushed a commit that referenced this issue Aug 31, 2022
## [3.0.5](v3.0.4...v3.0.5) (2022-08-31)

### Bug Fixes

* destroy sockets on close ([#204](#204)) ([e8b8f2e](e8b8f2e)), closes [#201](#201)
@github-actions
Copy link

🎉 This issue has been resolved in version 3.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@achingbrain
Copy link
Member

Possibly related, this may even be a dupe of #141

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

Successfully merging a pull request may close this issue.

2 participants