phoenix-channels
phoenix-channels copied to clipboard
Add an option to skip heartbeat
Phoenix by default sets up a heartbeat that runs every 30s and checks for disconnects.
It is possible to change the heartbeat time, but it is not possible to disable it altogether. This is a problem as
- The interval is not closed when
disconnect()
is called (disconnect first removes theonConnClose
handler that would close it) - The interval keeps node processes open.
There is logic to skip the heartbeat in the code (this.conn.skipHeartbeat
is checked when the connection is started), so we just need a way to set this property from the options passed into the Socket
module without having to create our own conn object or hacking WebSocket.
Pretty sure this is what's making jest throw Jest has detected the following 1 open handle potentially keeping Jest from exiting:
I fixed it like this
export async function disconnectSocket(client: Client) {
clearInterval(client.socket.heartbeatTimer)
await client.socket.disconnect(null, 1000, "Normal Disconnect")
return client
}
Bit messy cause I'm in the implementation, but I think I'll live.