Skip to content
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
19 changes: 10 additions & 9 deletions lib/livebook/hubs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ defmodule Livebook.Hubs do
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)
{:ok, _pid} =
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)

:ok
end
Expand Down
9 changes: 5 additions & 4 deletions lib/livebook/runtime/dependencies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ defmodule Livebook.Runtime.Dependencies do
def search_packages_on_hex(send_to, search) do
ref = make_ref()

Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
response = search_hex(search)
send(send_to, {:runtime_search_packages_response, ref, response})
end)
{:ok, _pid} =
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
response = search_hex(search)
send(send_to, {:runtime_search_packages_response, ref, response})
end)

ref
end
Expand Down
43 changes: 22 additions & 21 deletions lib/livebook/runtime/erl_dist/runtime_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,31 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServer do
if same_host?(pid) do
callback.(path)
else
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
md5 = file_md5(path)

target_path =
case GenServer.call(pid, {:transfer_file_open, file_id, md5}, :infinity) do
{:noop, target_path} ->
target_path

{:transfer, target_path, target_pid} ->
try do
path
|> File.stream!(64_000, [])
|> Enum.each(fn chunk -> IO.binwrite(target_pid, chunk) end)
{:ok, _pid} =
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
md5 = file_md5(path)

target_path =
case GenServer.call(pid, {:transfer_file_open, file_id, md5}, :infinity) do
{:noop, target_path} ->
target_path
rescue
_error -> nil
after
File.close(target_pid)
end
end

callback.(target_path)
end)
{:transfer, target_path, target_pid} ->
try do
path
|> File.stream!(64_000, [])
|> Enum.each(fn chunk -> IO.binwrite(target_pid, chunk) end)

target_path
rescue
_error -> nil
after
File.close(target_pid)
end
end

callback.(target_path)
end)
end

:ok
Expand Down
8 changes: 8 additions & 0 deletions test/livebook/runtime/dependencies_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ defmodule Livebook.Runtime.DependenciesTest do
end
end

describe "search_packages_on_hex/2" do
test "sends a response message to the caller with the search results" do
ref = Dependencies.search_packages_on_hex(self(), "")
assert is_reference(ref)
assert_receive {:runtime_search_packages_response, ^ref, {:ok, []}}
end
end

describe "search_hex/2" do
setup do
bypass = Bypass.open()
Expand Down
Loading