[Bug]: Registry server crashes when the update checker writes last_update after the registry was closed

Aperta Adatta ai principianti
#1,310 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
elixir, erlang
Ambito
backend, cli

Direzione di ricerca

Leggi gli handler :close e :last_update in lib/hex/registry/server.ex, poi segui la chiamata da lib/hex/update_checker.ex e le chiamate a :close in lib/mix/tasks/hex.package.ex. Verifica come si comporta l’handler quando lo stato del registro contiene ets: nil. Il lavoro è terminato quando una scrittura tardiva di last_update viene ignorata senza causare l’arresto anomalo del registro; aggiungi o aggiorna un test per questo caso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Product or component

hexpm/hex: Package manager client CLI and Mix task integration for Erlang/Elixir

Summary

The update checker's last_update write can reach a registry that its task already closed. handle_call({:last_update, time}, ...) then runs :ets.insert(nil, ...) and the registry server crashes. This is the crash in #936 and #996, both closed as not reproducible; below is the cause.

What happened?

Opening the registry casts Hex.UpdateChecker.start_check/0 (lib/hex/registry/server.ex, the :open handlers), which starts an async request for the Hex installs list. When it returns, Hex.UpdateChecker.handle_info/2 calls Hex.Registry.Server.last_update/1 (lib/hex/update_checker.ex, line 76).

Some tasks close the registry themselves before that request returns, for example mix hex.package fetch (lib/mix/tasks/hex.package.ex, the Hex.Registry.Server.close() calls). After :close the state has ets: nil, and lib/hex/registry/server.ex line 439 runs :ets.insert(state.ets, {:last_update, time}), which crashes the server. A caller waiting on the registry, such as a later close/0, receives that crash as an exit.

Because the write never lands, last_update is never saved, so a fresh HEX_HOME (for example in CI) runs the update check, and can hit this crash, on every command. In our CI it failed 2 of 2 runs on 2026-11-08.

What did you expect?

A last_update write after the registry was closed should be ignored, not crash the registry.

Steps to reproduce
  1. Use an empty HEX_HOME.
  2. Run mix hex.package fetch <package> <version> repeatedly.
  3. It crashes whenever the installs request returns after the task's own registry close. The timing varies; #936 shows the same crash from mix archive.install hex phx_new and #996 from Mix.install/1.
Environment / context
  • Hex 2.6.0; the same code is on main (2.8.0-dev, 986d4e6)
  • Elixir 1.20.4, Erlang/OTP 29.1.2
  • Linux, x86_64
Logs / screenshots
GenServer Hex.Registry.Server terminating
** (ArgumentError) errors were found at the given arguments:
  * 1st argument: the table identifier does not refer to an existing ETS table
    (stdlib) :ets.insert(nil, {:last_update, {{2026, 11, 8}, {15, 7, 42}}})
    (hex 2.6.0) lib/hex/registry/server.ex:439: Hex.Registry.Server.handle_call/3
Last message (from Hex.UpdateChecker): {:last_update, {{2026, 11, 8}, {15, 7, 42}}}
State: %{ets: nil, ...}
Additional context

Possible fix: ignore the write when the registry is closed, for example

def handle_call({:last_update, _time}, _from, %{ets: nil} = state) do
  {:reply, :ok, state}
end

or have the update checker skip last_update/1 when the registry is not open.

Lingua principale
Elixir
Stelle
1.1k
Fork
214
Merge medio
16h 50m
PR unite (30g)
38

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hexpm/hex

Tutte le issue di hexpm/hex

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.