phoenix-channels icon indicating copy to clipboard operation
phoenix-channels copied to clipboard

Add an option to skip heartbeat

Open dankelleher opened this issue 6 years ago • 2 comments

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

  1. The interval is not closed when disconnect() is called (disconnect first removes the onConnClose handler that would close it)
  2. 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.

dankelleher avatar Aug 23 '18 19:08 dankelleher

Pretty sure this is what's making jest throw Jest has detected the following 1 open handle potentially keeping Jest from exiting:

johns10 avatar Aug 14 '21 21:08 johns10

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.

johns10 avatar Aug 14 '21 21:08 johns10