fix: synchronous table startup for ETS/DETS/Counter adapters#44
Merged
Conversation
…eturns
Cache.ETS, Cache.DETS, and Cache.Counter all used Task.start_link to
spawn a hibernating owner process, but the table setup ran inside the
task. start_link returned as soon as the task was spawned, so the
supervisor considered the child started before the table actually
existed — callers that touched the cache immediately after the
supervisor came up could hit a missing table.
Each adapter's task now sends a :ready signal back to the parent after
setup, and start_link blocks on that signal (or on {:EXIT, pid, reason}
if setup crashes). The supervisor sees a genuinely synchronous start.
Cache.PersistentTerm has no setup and Cache.RefreshAhead.start_tracker
already creates its table before Task.start_link, so neither needs the
handshake.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #44 +/- ##
==========================================
- Coverage 83.46% 83.46% -0.01%
==========================================
Files 22 22
Lines 617 635 +18
==========================================
+ Hits 515 530 +15
- Misses 102 105 +3 ☔ View full report in Codecov by Sentry. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Cache.ETS,Cache.DETS, andCache.Counterall wrapped their setup inTask.start_link(fn -> ... end). The task spawned,start_linkreturned{:ok, pid}, and the supervisor moved on — but the table creation/opening was still running inside the task. Callers that hit the cache immediately after the supervisor came up could see a missing table.:readysignal back to the parent after setup completes;start_linkblocks on that signal (or on{:EXIT, pid, reason}if setup crashes), giving the supervisor a genuinely synchronous start.Cache.PersistentTermhas no setup work, andCache.RefreshAhead.start_trackeralready creates its tracker ETS table beforeTask.start_linkruns — neither has a race, so both were left alone.Test plan
mix test test/cache/ets_test.exs test/cache/dets_test.exs test/cache/counter_test.exs— 85 tests, 0 failuresmix credo --strict lib/cache/ets.ex lib/cache/dets.ex lib/cache/counter.ex— no issuesstart_supervised!followed by an immediateget/put(noProcess.sleep) passes against the patched code, confirming the table is ready the momentstart_linkreturns.Follow-up (not in this PR)
The
Process.sleep(100)calls scattered across the existing ETS/DETS/Counter tests are now unnecessary and can be removed in a follow-up cleanup.