denoland/deno

Feature request: Keep-alive for TCP

Closed this issue · 0 comments

From RFC1122 4.2.3.6,

Implementors MAY include "keep-alives" in their TCP
implementations, although this practice is not universally
accepted.  If keep-alives are included, the application MUST
be able to turn them on or off for each TCP connection, and
they MUST default to off.

Currently, Deno.listen and Deno.connect occasionally seem to become stale when kept open for a while without any packets (a waiting connection). It doesn't close the connection, and doesn't error out, just becomes unresponsive on both sides until you try to write a packet. This causes me to be unable to free up resources from zombie connections.

As far as I understand, this is due to not sending keep-alive probes. Node has the socket.setKeepAlive API that I'm missing on Deno.

Implementing this might simply be setting the SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPCNT, TCP_KEEPINTVL options on the socket Linux Windows.

A possible Deno API may look like conn.setKeepAlive(interval)

Further reading:

I found this article that seems to describe the exact behaviour I'm facing, and the solution (keep-alive): https://holmeshe.me/network-essentials-setsockopt-SO_KEEPALIVE/#To-detect-an-absent-peer