Skip to content

Conversation

@perzanko
Copy link

@perzanko perzanko commented Feb 6, 2026

Problem

When using SSE-based subscriptions (standard_sse: true in absinthe_plug), active connections call unsubscribe/2 during connection teardown. In a standard supervision tree where Absinthe.Subscription is started after the Endpoint (as documented), OTP terminates children in reverse start order — meaning the subscription Registry is shut down before the Endpoint finishes draining connections.

This causes an ArgumentError: unknown registry from Registry.unregister_match/4 during every deployment for each active SSE subscription.

Elixir.ArgumentError: unknown registry: MyAppWeb.Endpoint.Registry
    (elixir 1.19.5) lib/registry.ex:1551: Registry.info!/1
    (elixir 1.19.5) lib/registry.ex:1073: Registry.unregister_match/4
    (absinthe 1.9.0) lib/absinthe/subscription.ex:183: anonymous fn/4 in Absinthe.Subscription.unsubscribe/2
    ...
    (absinthe_plug 1.5.9) lib/absinthe/plug.ex:399: Absinthe.Plug.subscribe_loop/3

Fix

Guard against the missing registry using Process.whereis/1 in unsubscribe/2, following the same pattern already used in extract_pubsub/2.

The process dictionary cleanup (pdict_delete_fields) always runs regardless, so there's no resource leak.

When using SSE-based subscriptions (standard_sse: true in absinthe_plug),
active connections call unsubscribe/2 during connection teardown. In a
standard supervision tree where Absinthe.Subscription is started after
the Endpoint (as documented), OTP terminates children in reverse start
order - meaning the subscription Registry is shut down before the
Endpoint finishes draining connections. This causes an ArgumentError
from Registry.unregister_match/4.

Guard against the missing registry using Process.whereis/1, following
the same pattern already used in extract_pubsub/2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@perzanko perzanko changed the title Handle missing registry in Subscription.unsubscribe/2 during shutdown fix: Handle missing registry in Subscription.unsubscribe/2 during shutdown Feb 6, 2026
@perzanko perzanko marked this pull request as ready for review February 6, 2026 17:08
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.

2 participants