-
Notifications
You must be signed in to change notification settings - Fork 120
Fix Watcher blocking during slow pool termination #343
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a7c73e
Add failing test for Watcher contention during pool termination
v0idpwn 867dade
Make watcher shut down the pool supervisor async
v0idpwn de36728
Make test concurrency safe
v0idpwn bbc5943
fmt
v0idpwn e6bb745
Improve test
v0idpwn bb7e167
Handle nil caller pid on terminate
v0idpwn 7aa509a
Use sys:terminate to avoid spawning a task
v0idpwn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| defmodule DBConnection.WatcherTest do | ||
| use ExUnit.Case, async: true | ||
|
|
||
| alias TestConnection, as: C | ||
| alias TestAgent, as: A | ||
|
|
||
| test "starting a new pool is not blocked by a slow-to-terminate pool" do | ||
| {:ok, agent1} = | ||
| A.start_link([ | ||
| {:ok, :state}, | ||
| fn _err, _state -> | ||
| Process.sleep(10_000) | ||
| :ok | ||
| end | ||
| ]) | ||
|
|
||
| pool1 = | ||
| start_supervised!(%{ | ||
| id: :pool1, | ||
| start: | ||
| {DBConnection, :start_link, | ||
| [ | ||
| TestConnection, | ||
| [agent: agent1, pool_size: 1, idle_interval: 100_000, shutdown: 2_500] | ||
| ]}, | ||
| restart: :temporary | ||
| }) | ||
|
|
||
| # Find the pool sup for pool1 by matching the owner pid in child spec ids. | ||
| pool_sup_ref = | ||
| DBConnection.ConnectionPool.Supervisor | ||
| |> DynamicSupervisor.which_children() | ||
| |> Enum.find_value(fn {_, sup_pid, _, _} -> | ||
| try do | ||
| has_pool1? = | ||
| sup_pid | ||
| |> Supervisor.which_children() | ||
| |> Enum.any?(fn {{_mod, owner, _id}, _, _, _} -> owner == pool1 end) | ||
|
|
||
| if has_pool1?, do: sup_pid | ||
| catch | ||
| :exit, _ -> nil | ||
| end | ||
| end) | ||
| |> Process.monitor() | ||
|
|
||
| # Trigger pool termination | ||
| stop_supervised!(:pool1) | ||
|
|
||
| {:ok, agent2} = A.start_link([{:ok, :state}]) | ||
|
|
||
| task = | ||
| Task.async(fn -> | ||
| C.start_link(agent: agent2, pool_size: 1, idle_interval: 100_000) | ||
| end) | ||
|
|
||
| # If the DynamicSupervisor or the watcher is blocked, this hangs | ||
| assert {:ok, _pool2} = Task.await(task, 1_000) | ||
|
|
||
| # Ensure the pool supervisor actually terminates | ||
| assert_receive {:DOWN, ^pool_sup_ref, _, _, _}, 5_000 | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary because now we keep
ref => {nil, nil}when a termination is on flight