From c6a812c19a968726b48ce972d0822883ed58847a Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Thu, 13 Apr 2023 21:16:38 +0700 Subject: [PATCH 1/6] fix link --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c435297..b132e68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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 From 0449a893c21335c30738d782f8b27554c519e86a Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Sat, 15 Apr 2023 16:18:06 +0700 Subject: [PATCH 2/6] Update elixir/otp in .tool-versions --- .tool-versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index 4d82a50..600e369 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 25.2.1 -elixir 1.14.3-otp-25 +erlang 25.3 +elixir 1.14.4-otp-25 From 118bcde1a6483b33fe2ceeefa4fa340c407b5326 Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Sun, 14 May 2023 14:02:24 +0700 Subject: [PATCH 3/6] Credo strict checks (#42) --- .credo.exs | 2 +- lib/poolex/busy_workers.ex | 2 +- lib/poolex/waiting_callers.ex | 2 +- lib/poolex/workers/impl/erlang_queue.ex | 2 +- lib/poolex/workers/impl/list.ex | 2 +- test/support/some_busy_workers_impl.ex | 2 +- test/support/some_idle_workers_impl.ex | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) 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/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/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/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 From 7ef07ce6fe5e92361159304bc8493f81b6d91133 Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Mon, 22 May 2023 19:45:05 +0700 Subject: [PATCH 4/6] Add OTP 26 to CI (#43) --- .github/workflows/ci-tests.yml | 4 +++- .tool-versions | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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 600e369..dc8d7e4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 25.3 -elixir 1.14.4-otp-25 +erlang 26.0 +elixir 1.14.4-otp-26 From a87a511b13ca76823b7e38264af99c3cf3cadf34 Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Sat, 3 Jun 2023 13:28:29 +0700 Subject: [PATCH 5/6] Handle shutdown process (#45) * Test: workers stop before the pool * Stop supervisor on pool terminating * Destroy monitoring table on pool terminating * Update CHANGELOG --- CHANGELOG.md | 4 ++++ lib/poolex.ex | 8 ++++++++ lib/poolex/monitoring.ex | 8 ++++++++ test/poolex_test.exs | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b132e68..fd4139d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### 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 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/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/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) From 2a6c119754c16d62383c75804e4f5cb127e3fd1d Mon Sep 17 00:00:00 2001 From: Aleksandr Sysoev Date: Sat, 3 Jun 2023 13:36:10 +0700 Subject: [PATCH 6/6] Release v0.7.1 --- CHANGELOG.md | 7 +++++-- mix.exs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4139d..6e2c705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ 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)). @@ -15,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added `FIFO` worker's implementation. [About implemetations](https://hexdocs.pm/poolex/workers-and-callers-implementations.html) +- Added `FIFO` worker's implementation ([About implemetations](https://hexdocs.pm/poolex/workers-and-callers-implementations.html)). ## [0.6.1] - 2023-03-25 @@ -165,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/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