diff --git a/.credo.exs b/.credo.exs index 9965c2f..874f101 100644 --- a/.credo.exs +++ b/.credo.exs @@ -46,7 +46,7 @@ # If you want to enforce a style guide and need a more traditional linting # experience, you can change `strict` to `true` below: # - strict: false, + strict: true, # # To modify the timeout for parsing files, change this value: # diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 0d15300..bad4030 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -32,6 +32,8 @@ jobs: otp: '25' - elixir: '1.14' otp: '25' + - elixir: '1.14' + otp: '26' steps: - uses: actions/checkout@v3 - uses: erlef/setup-beam@v1 @@ -63,7 +65,7 @@ jobs: - name: Run dialyzer uses: erlef/setup-beam@v1 with: - otp-version: '25' + otp-version: '26' elixir-version: '1.14' - run: mix do deps.get, compile - run: mix check diff --git a/.tool-versions b/.tool-versions index 4d82a50..dc8d7e4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 25.2.1 -elixir 1.14.3-otp-25 +erlang 26.0 +elixir 1.14.4-otp-26 diff --git a/CHANGELOG.md b/CHANGELOG.md index c435297..6e2c705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.7.1] - 2023-06-03 + +### Fixed + +- Fix the shutdown process: stop workers before the pool ([issue](https://github.com/general-CbIC/poolex/issues/44)). + ## [0.7.0] - 2023-04-13 ### Added -- Added `FIFO` worker's implementation. [About implemetations](https://hexdocs.pm/poolex/custom-implementations.html) +- Added `FIFO` worker's implementation ([About implemetations](https://hexdocs.pm/poolex/workers-and-callers-implementations.html)). ## [0.6.1] - 2023-03-25 @@ -161,7 +167,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Supported main interface `Poolex.run/3` with `:timeout` option. -[unreleased]: https://github.com/general-CbIC/poolex/compare/v0.7.0...HEAD +[unreleased]: https://github.com/general-CbIC/poolex/compare/v0.7.1...HEAD +[0.7.1]: https://github.com/general-CbIC/poolex/compare/v0.7.0...v0.7.1 [0.7.0]: https://github.com/general-CbIC/poolex/compare/v0.6.1...v0.7.0 [0.6.1]: https://github.com/general-CbIC/poolex/compare/v0.6.0...v0.6.1 [0.6.0]: https://github.com/general-CbIC/poolex/compare/v0.5.1...v0.6.0 diff --git a/lib/poolex.ex b/lib/poolex.ex index bb8fd2f..c130c6b 100644 --- a/lib/poolex.ex +++ b/lib/poolex.ex @@ -472,4 +472,12 @@ defmodule Poolex do {:noreply, %{state | waiting_callers_state: new_waiting_callers_state}} end end + + @impl GenServer + def terminate(reason, %State{} = state) do + DynamicSupervisor.stop(state.supervisor, reason) + Monitoring.stop(state.monitor_id) + + :ok + end end diff --git a/lib/poolex/busy_workers.ex b/lib/poolex/busy_workers.ex index 6bc6f30..b2c7d3d 100644 --- a/lib/poolex/busy_workers.ex +++ b/lib/poolex/busy_workers.ex @@ -1,7 +1,7 @@ defmodule Poolex.BusyWorkers do @moduledoc false - alias Poolex.Workers.Behaviour alias Poolex.Settings + alias Poolex.Workers.Behaviour @doc false @spec init(Poolex.pool_id(), module()) :: Behaviour.state() diff --git a/lib/poolex/monitoring.ex b/lib/poolex/monitoring.ex index 7acee15..3f4a682 100644 --- a/lib/poolex/monitoring.ex +++ b/lib/poolex/monitoring.ex @@ -11,6 +11,14 @@ defmodule Poolex.Monitoring do {:ok, monitor_id} end + @spec stop(monitor_id()) :: :ok + @doc false + def stop(monitor_id) do + :ets.delete(monitor_id) + + :ok + end + @spec add(monitor_id(), pid(), kind_of_process()) :: :ok @doc false def add(monitor_id, process_pid, kind_of_process) do diff --git a/lib/poolex/waiting_callers.ex b/lib/poolex/waiting_callers.ex index 1446812..8f4508b 100644 --- a/lib/poolex/waiting_callers.ex +++ b/lib/poolex/waiting_callers.ex @@ -1,7 +1,7 @@ defmodule Poolex.WaitingCallers do @moduledoc false - alias Poolex.Settings alias Poolex.Callers.Behaviour + alias Poolex.Settings @doc false @spec init(Poolex.pool_id(), module()) :: Behaviour.state() diff --git a/lib/poolex/workers/impl/erlang_queue.ex b/lib/poolex/workers/impl/erlang_queue.ex index dd9b663..67d34b3 100644 --- a/lib/poolex/workers/impl/erlang_queue.ex +++ b/lib/poolex/workers/impl/erlang_queue.ex @@ -5,7 +5,7 @@ defmodule Poolex.Workers.Impl.ErlangQueue do @behaviour Poolex.Workers.Behaviour @impl true - def init() do + def init do :queue.new() end diff --git a/lib/poolex/workers/impl/list.ex b/lib/poolex/workers/impl/list.ex index 1a28708..588fb68 100644 --- a/lib/poolex/workers/impl/list.ex +++ b/lib/poolex/workers/impl/list.ex @@ -5,7 +5,7 @@ defmodule Poolex.Workers.Impl.List do @behaviour Poolex.Workers.Behaviour @impl true - def init() do + def init do [] end diff --git a/mix.exs b/mix.exs index 9c46a65..1d400b1 100644 --- a/mix.exs +++ b/mix.exs @@ -15,7 +15,7 @@ defmodule Poolex.MixProject do package: package(), source_url: "https://github.com/general-CbIC/poolex", start_permanent: Mix.env() == :prod, - version: "0.7.0" + version: "0.7.1" ] end diff --git a/test/poolex_test.exs b/test/poolex_test.exs index da57ede..a41c603 100644 --- a/test/poolex_test.exs +++ b/test/poolex_test.exs @@ -372,6 +372,30 @@ defmodule PoolexTest do end end + describe "shutdown process" do + test "workers stop before the pool", %{pool_name: pool_name} do + {:ok, pool_pid} = + Poolex.start_link(pool_id: pool_name, worker_module: SomeWorker, workers_count: 1) + + state = Poolex.get_state(pool_name) + + supervisor_pid = state.supervisor + worker_pid = Poolex.run!(pool_name, fn pid -> pid end) + + pool_monitor_ref = Process.monitor(pool_pid) + supervisor_monitor_ref = Process.monitor(supervisor_pid) + worker_monitor_ref = Process.monitor(worker_pid) + + GenServer.stop(pool_name) + + {:messages, [message_1, message_2, message_3]} = Process.info(self(), :messages) + + assert message_1 == {:DOWN, worker_monitor_ref, :process, worker_pid, :shutdown} + assert message_2 == {:DOWN, supervisor_monitor_ref, :process, supervisor_pid, :normal} + assert message_3 == {:DOWN, pool_monitor_ref, :process, pool_pid, :normal} + end + end + defp pool_name do 1..10 |> Enum.map(fn _ -> Enum.random(?a..?z) end) diff --git a/test/support/some_busy_workers_impl.ex b/test/support/some_busy_workers_impl.ex index e847f43..19a27aa 100644 --- a/test/support/some_busy_workers_impl.ex +++ b/test/support/some_busy_workers_impl.ex @@ -3,7 +3,7 @@ defmodule SomeBusyWorkersImpl do @behaviour Poolex.Workers.Behaviour @impl true - def init() do + def init do [] end diff --git a/test/support/some_idle_workers_impl.ex b/test/support/some_idle_workers_impl.ex index 3aaec8d..293189e 100644 --- a/test/support/some_idle_workers_impl.ex +++ b/test/support/some_idle_workers_impl.ex @@ -3,7 +3,7 @@ defmodule SomeIdleWorkersImpl do @behaviour Poolex.Workers.Behaviour @impl true - def init() do + def init do [] end