Don't reconnect when WebSocket returns server error (#2264)

This commit is contained in:
Alexandre de Souza 2023-10-10 18:51:38 -03:00 committed by GitHub
parent 4665e755a3
commit 2898ee37f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -128,7 +128,14 @@ defmodule Livebook.Hubs do
end
defp disconnect_hub(hub) do
# We use a task supervisor because the hub connection itself
# calls delete_hub (which calls this function), otherwise we deadlock.
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
# Since other processes may have been communicating
# with the hub, we don't want to terminate abruptly and
# make them crash, so we give it some time to shut down.
#
# The default backoff is 5.5s, so we round it down to 5s.
Process.sleep(30_000)
:ok = Provider.disconnect(hub)
end)

View file

@ -52,7 +52,7 @@ defmodule Livebook.Teams.Connection do
reason = LivebookProto.Error.decode(error).details
send(data.listener, {:server_error, reason})
{:keep_state_and_data, {{:timeout, :reconnect}, @backoff, nil}}
{:keep_state, data}
end
end
@ -60,10 +60,6 @@ defmodule Livebook.Teams.Connection do
{:keep_state_and_data, {:next_event, :internal, :connect}}
end
def handle_event({:timeout, :reconnect}, nil, _state, _data) do
{:keep_state_and_data, {:next_event, :internal, :connect}}
end
def handle_event(:info, {:loop_ping, ref}, @no_state, %__MODULE__{ref: ref} = data) do
case WebSocket.send(data.http_conn, data.websocket, data.ref, :ping) do
{:ok, conn, websocket} ->