runreflect / agent

The Reflect Agent allows secure connections between Reflect's cloud browsers and private web applications.
MIT License
5 stars 0 forks source link

Add a flag for a heartbeat or periodic message on the websocket #17

Closed fitzn closed 1 year ago

fitzn commented 1 year ago

We've seen cases where a misbehaving NAT will terminate the long-running websocket connection when it's idle and not send a FIN packet to the agent code. When this happens, the agent does not know that the connection is terminated, and the agent will not trigger its automatic reconnect logic.

One way to handle this is to have the agent periodically send a packet (e.g., the sessions command) every minute or less to make it appear to the NAT that the connection is still in use. This is what the agent already does for the UDP connections that actually carry the browser session data.

The current implementation of the agent code only sends a single sessions command on the long-running websocket connection and then it closes the input stream since it doesn't need to send any additional information. (All information after the initial connection from the agent comes from the Reflect API.) So, making this change will require modifying the STDIN pipe to the websocat process and potentially changing how the input is generated.