Skip to content

Commit

Permalink
chore: spawn linked async req process in http1 pool
Browse files Browse the repository at this point in the history
I wanted to remove the process monitoring, but without the async request
actively monitoring the calling process, the request wasn't being
short-circuited when the caller exited. I'm not entirely sure why.
  • Loading branch information
zachallaun committed Jun 11, 2023
1 parent 8bae1ce commit 9ae43ef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/finch/http1/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule Finch.HTTP1.Pool do
owner = self()

pid =
spawn(fn ->
spawn_link(fn ->
monitor = Process.monitor(owner)
request_ref = receive_next_within!(10)

Expand Down Expand Up @@ -120,6 +120,7 @@ defmodule Finch.HTTP1.Pool do

@impl Finch.Pool
def cancel_async_request({_, _, _, pid}) do
Process.unlink(pid)
Process.exit(pid, :shutdown)
:ok
end
Expand Down
2 changes: 1 addition & 1 deletion test/finch/http1/pool_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ defmodule Finch.HTTP1.PoolTest do

assert_receive {:req_pid, pid}

Process.exit(caller, :kill)
Process.exit(caller, :shutdown)
Process.sleep(200)

refute Process.alive?(pid)
Expand Down

0 comments on commit 9ae43ef

Please sign in to comment.