Skip to content

Fix type errors while another connection loads types - #802

Merged
josevalim merged 1 commit into
elixir-ecto:masterfrom
cyrilghali:fix-type-reload-race
Oct 8, 2026
Merged

josevalim merged 1 commit into
elixir-ecto:masterfrom
cyrilghali:fix-type-reload-race

Conversation

@cyrilghali

Copy link
Copy Markdown
Contributor

A query can fail with "type x can not be handled by the types module" while another connection is still loading new types, although the type works a moment later. Types still loading now count as unknown, so the query waits for them and succeeds. A type that stays unsupported still fails as before.

The new test fails on master, where a type still loading is reported as unsupported. The full suite passes against PostgreSQL 17, and the issue's script (10 concurrent inserts while 10,000 types load) goes from 10 failed inserts to 0.

Fixes #801

While a connection loads a batch of new types, other connections read
the table without the type server lock. Each entry briefly holds nil,
which means unsupported, so a query can fail with "type `x` can not
be handled by the types module" for a type that works a moment later.

Entries now hold :associating until they are resolved. fetch/2 treats
that as unknown, so the caller reloads, waits on the type server for
the batch to finish, and reads the finished entry. Types that end up
unsupported still store nil and fail as before. The type server owns
the table, so a crash mid-batch cannot leave the marker behind.
Anonymous records decoded during the window still raise, now with
"was not bootstrapped" instead of "can not be handled".

Fixes elixir-ecto#801
@cyrilghali
cyrilghali marked this pull request as ready for review October 7, 2026 21:59
@josevalim
josevalim merged commit 4ed83cd into elixir-ecto:master Oct 8, 2026
12 of 13 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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.

Race in type reload: concurrent query sees "type x can not be handled" while another connection associates it

2 participants