Connection with websockets is closed after a few seconds

Hello, I'm doing my first tests with Zrok, for this I'm using an application I developed, it consists of a web interface in ReactJs that uses websockets to receive notifications from the backend. Whenever the user logs into the application, a websocket connection (wss://) is established using the same https port (https://), and should stay that way until the user disconnects. If the connection to this websocket is lost, the application will lock the screen, warning you about the disconnection, and try to reconnect after a few seconds.

I'm using the command: zrok share reserved, everything seems to work normally when the user logs in. But when I stop interacting with the web interface, and just look at it for about 1 minute, the connection to the websocket is closed, the application shows this to the user, and tries to reconnect, it manages to connect again, but after 1 minute the disconnection occurs again.

Is there any time limitation that a websocket connection can remain open without executing any requests?

When I access this same application without using Zrok, this problem does not occur.

Here are the messages I get when the connection is closed:

¦(msg type: 60786) ¦
¦[ 77,774] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).Read: {marker=[9l4jyAu8] connId=[2147483649]} reading 1004 bytes ¦
¦[ 77,867] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).Read: {connId=[2147483649] marker=[9l4jyAu8]} unexpected sequencer err (read timed out) ¦
¦[ 77,867] DEBUG sdk-golang/ziti/edge.(*MsgChannel).WriteTraced: {edgeSeq=[2] connId=[2147483649] type=[EdgeDataType] chSeq=[-1]} writing 167 bytes ¦
¦[ 77,882] DEBUG sdk-golang/ziti/edge.(*MsgChannel).WriteTraced: {type=[EdgeDataType] chSeq=[-1] edgeSeq=[3] connId=[2147483649]} writing 163 bytes ¦
¦[ 137,998] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).Accept: {connId=[2147483649] type=[EdgeStateClosedType] chSeq=[15] edgeSeq=[3]} received 12 ¦
¦bytes (msg type: 60785) ¦
¦[ 137,998] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).Read: {connId=[2147483649] marker=[9l4jyAu8]} received ConnState_CLOSED message, closing ¦
¦connection¦
¦[ 137,998] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).close: {connId=[2147483649] marker=[9l4jyAu8]} close: begin ¦
¦[ 138,002] DEBUG sdk-golang/ziti/edge/network.(*edgeConn).close: {connId=[2147483649] marker=[9l4jyAu8]} close: end

Hi @giorgiobazzo welcome to the community and to zrok (and OpenZiti)!

I'm actually not sure, I've never tested this myself. I'll ask the team to see if anyone else has tried it or knows if the websocket closes after a minute. That obviously won't work out too well for websocket...

Thank you very much for your attention @TheLumberjack ,

Zrok and OpenZiti are wonderful solutions, I've been looking for something similar for a while, and I finally think I found it. Congratulations to everyone who made this possible.

An update on this issue with websockets:

Today I timed the disconnections, and they occur exactly every 60 seconds of inactivity. I implemented a ping routine on the server side, which every 30 seconds pings all clients connected via websockets. This appears to have resolved the issue as it has now been over 15 minutes without disconnecting. So this reinforces my suspicion, that there is a timeout for inactivity of a websocket connection.

Thanks!

1 Like

Glad to hear you solved the issue and we're happy you're enjoying zrok and OpenZiti! Cheers

Hey @giorgiobazzo - you are correct, we do close inactive connections after 60 seconds as a necessary protection for the cloud service, I believe your workaround should work for your use case. If you find yourself still being disconnected with that keepalive ping let us know and we'll dig into it some more on our side.

Thanks @mguthrie88, for the information about the 60 second limit.
Pinging every 30 seconds seems to be working fine.