Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reconnect when WebSocket returns server error #2264

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/livebook/hubs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
aleDsz marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Expand Down
6 changes: 1 addition & 5 deletions lib/livebook/teams/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,14 @@ 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

def handle_event({:timeout, :backoff}, nil, _state, _data) 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} ->
Expand Down
Loading