Skip to content

Explicitly reject simple_one_for_one worker supervision - #224

Open
vkatsuba wants to merge 1 commit into
inaka:mainfrom
vkatsuba:issue-172-doc
Open

vkatsuba wants to merge 1 commit into
inaka:mainfrom
vkatsuba:issue-172-doc

Conversation

@vkatsuba

Copy link
Copy Markdown
Contributor

Summary

Closes #172 — Asynchronous shutdown of workers.

Problem and resulting behavior

The strategy pool option accepts OTP supervisor flags, but the pool creates an individual static child specification for each worker. This initialization model does not support simple_one_for_one, which requires a single child template and explicit dynamic child startup.

Previously, selecting this strategy did not produce a deliberate, library-specific rejection. Its behavior depended on whether OTP accepted the generated child specifications; a single-worker pool could get past that validation despite the strategy not being supported by the library.

This PR explicitly rejects simple_one_for_one before starting the worker supervisor and documents the supported strategies. Pool startup now fails with the reason:

{unsupported_strategy, simple_one_for_one}

Maintainer direction and related discussion

This follows the maintainer's decision to exclude the strategy rather than introduce additional worker startup and shutdown behavior:

The approach here implements that exclusion with a small runtime check, documentation, and a regression test. It does not introduce support for parallel worker shutdown or the additional lifecycle code discussed in #223.

Implementation

Explicit rejection

Two clauses added to wpool_process_sup:start_link/3 reject the strategy in either supervisor flag format:

#{strategy => {simple_one_for_one, 5, 60}}
#{strategy => #{strategy => simple_one_for_one}}

Both return:

{error, {unsupported_strategy, simple_one_for_one}}

The existing startup clause remains unchanged for other configurations. The check runs before the worker supervisor starts, so the rejected strategy does not start workers.

For a pool started with wpool:start_sup_pool/2, OTP propagates the error through the existing supervision hierarchy:

{error,
    {shutdown,
        {failed_to_start_child, WorkerSupervisorName,
            {unsupported_strategy, simple_one_for_one}}}}

The executable production change consists of four added lines in wpool_process_sup.erl.

Documentation

The README and the option/0 and options/0 documentation now state that the supported worker supervision strategies are:

  • one_for_one, the default.
  • one_for_all.
  • rest_for_one.

They explain why simple_one_for_one is unsupported and identify its startup error reason. The README also distinguishes the supervisor strategy configured by the pool option from the worker selection strategy passed to functions such as wpool:call.

Scope and compatibility

The intentional behavior change is limited to selecting the unsupported simple_one_for_one strategy: it now fails explicitly and consistently, including for single-worker pools.

For supported strategies, this PR preserves the existing startup implementation, application supervision tree, worker specifications, names, restart policy, and shutdown timeouts. It adds no public API or configuration options.

Regression test

One Common Test case, unsupported_supervisor_strategy/1, covers eight combinations:

Configuration dimension Values
Supervisor flags Tuple and map
Pool options List and map
Worker count One and two

For each combination, the test verifies:

  • Supervised pool startup fails with the expected nested unsupported_strategy reason.
  • The pool name is not registered after startup fails.
  • The first worker name is not registered after startup fails.

The single-worker cases ensure rejection is not dependent on OTP rejecting multiple child specifications for a simple_one_for_one supervisor.

Validation

Local checks were run on OTP 28.5:

Check Result
Full Common Test suite All 57 tests passed
New regression test Passed all eight configuration combinations
Overall coverage 92.03%, above the configured 90% minimum
wpool_process_sup coverage 100%
Formatting Passed
Lint Passed
Hank Passed with existing ignored warnings
Xref Passed
Dialyzer Five existing warnings in existing tests

Dialyzer is not reported as passing: it still exits with the existing warnings concerning cthr:pal/2, unmatched return values, and the existing complete_coverage/1 specification/contract checks. No new warnings were reported for the added rejection clauses or regression test.

OTP 29 was not tested locally and remains for CI validation.

Reject simple_one_for_one in both tuple and map supervisor flags with
an {unsupported_strategy, simple_one_for_one} error reason.

Document the supported worker supervision strategies and clarify that
parallel shutdown through simple_one_for_one is not available.

Add a regression test covering tuple/map flags, list/map pool options,
and pools with one or two workers.

Validation on OTP 28.5:
- All 57 tests pass; total coverage is 92%.
- Formatting, lint, hank, and xref checks pass.
- Dialyzer reports five existing test warnings.

Closes inaka#172
@vkatsuba

Copy link
Copy Markdown
Contributor Author

@elbrujohalcon please take a look to this PR when you will have a time.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.03%. Comparing base (eace4a7) to head (c7a4b70).
⚠️ Report is 66 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #224      +/-   ##
==========================================
- Coverage   92.57%   92.03%   -0.55%     
==========================================
  Files          10       10              
  Lines         458      527      +69     
==========================================
+ Hits          424      485      +61     
- Misses         34       42       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Asynchronous shutdown of workers

1 participant