Skip to content

Backport: fix FunctionClauseError in disconnect handler (0.11.x)#533

Open
saner wants to merge 37 commits intoelixir-grpc:release/v0.11.3from
saner:fix/disconnect-function-clause-error
Open

Backport: fix FunctionClauseError in disconnect handler (0.11.x)#533
saner wants to merge 37 commits intoelixir-grpc:release/v0.11.3from
saner:fix/disconnect-function-clause-error

Conversation

@saner
Copy link
Copy Markdown

@saner saner commented May 4, 2026

Summary

Backport of #493 to the 0.11.x line (branched from v0.11.5).

GRPC.Client.Connection.handle_call/3 for {:disconnect, ...} only pattern-matches {_key, {:ok, ch}} when iterating state.real_channels. However, build_real_channels/4 can store {:error, reason} entries for failed connections, causing a FunctionClauseError on disconnect.

This is the same fix merged via #493 for 1.0.0-rc:

  • Add a catch-all _ -> :ok clause to skip channels that failed to connect
  • Wrap adapter.disconnect/1 in do_disconnect/2 with rescue/catch for resilience

Related issues

Test plan

  • Existing integration tests pass (mix test)
  • Verified fix matches upstream commit 4052c86

🤖 Generated with Claude Code

Adriano Santos and others added 30 commits May 9, 2025 23:29
….run (elixir-grpc#453)

* fix: GRPC.Stream.run only consumes the first reply and returns :ok

* fix: simplify noreply workflow
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
* chore: release new version

* bump 0.10.2 -> 0.11.0

* refactor: better extract_subtype invalid type message and change log level

* chore: use warning log level

---------

Co-authored-by: Adriano Santos <adriano.santos@v3.com.br>
* fix: refresh error spam on direct_state (no lb)

* chore: formatting connection module

---------

Co-authored-by: joeri dijkstra <joeri.dijkstra@bettyblocks.com>
* chore: release new version

* bump 0.10.2 -> 0.11.0

* feat: added new function to handle side-effects

* chore: added doc, remove comments

* feat: added error handler unary and stream pipelines

* test: added many more tests

* Update lib/grpc/stream.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update lib/grpc/stream.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* fix: correct return type in doc

* Update lib/grpc/stream/operators.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* chore: updated after review

* docs: adds a better explanation of the different types of input

* mix format

* test: reintroduces tests that were removed by mistake

* docs: introduces documentation for error handling and side effects

* Update README.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update README.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update lib/grpc/stream.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update test/grpc/integration/server_test.exs

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update test/grpc/stream_test.exs

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update test/grpc/stream_test.exs

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* chore: resolve review comments

* chore: remove markdown clutter

---------

Co-authored-by: Adriano Santos <adriano.santos@v3.com.br>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
* chore: release new version

* bump 0.10.2 -> 0.11.0

* docs: try more professional documentation

* formatting

* temporary remove warning as errors

* chore: remove deprecated annotation

* Update guides/getting_started/client.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update guides/getting_started/installation.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update guides/getting_started/installation.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update guides/getting_started/installation.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update guides/getting_started/introduction.md

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* chore: adjustments after review

* chore: added header

* Update lib/grpc/server.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update lib/grpc/stream.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* Update lib/grpc/stream.ex

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>

* doc: added flush function

* doc: rename :utility to :actions

* docs: update and adjustments

* chore: remove subproject examples

---------

Co-authored-by: Adriano Santos <adriano.santos@v3.com.br>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
* chore: release new version

* bump 0.10.2 -> 0.11.0

* fix: correct struct syntax

---------

Co-authored-by: Adriano Santos <adriano.santos@v3.com.br>
* chore: release new version

* bump 0.10.2 -> 0.11.0

* fix: correct struct syntax

* bump v0.11.3 -> v0.11.4

---------

Co-authored-by: Adriano Santos <adriano.santos@v3.com.br>
ollien and others added 5 commits November 7, 2025 20:43
* Add `exception_log_filter` option to server

* Only allow MF form

* refactor: more flexible filtering

* chore: format

* test: improve test

* chore: format

* fix test

---------

Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
* Ensure 1 GRPC.Client.Supervisor

* Update lib/grpc/client/supervisor.ex

* Format code - verify author

---------

Co-authored-by: Micah Cooper <micah.cooper@mimic.com>
Co-authored-by: Adriano Santos <solid.sistemas@gmail.com>
Co-authored-by: Micah Cooper <mrmichacooper@gmail.com>
@saner
Copy link
Copy Markdown
Author

saner commented May 4, 2026

Note: this branch is based on tag v0.11.5, not release/v0.11.3. Could you create a release/v0.11.5 branch from the tag and retarget this PR? That way the diff will be clean — just the single fix commit.

Backport of elixir-grpc#493 to the 0.11.x branch. When `build_real_channels`
stores `{:error, reason}` entries for failed connections, the
disconnect handler crashes because it only pattern-matches
`{:ok, ch}` tuples.

Add a catch-all clause to skip failed channels and wrap
`adapter.disconnect/1` in a rescue/catch to prevent crashes
from propagating.

Fixes elixir-grpc#492

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@saner saner force-pushed the fix/disconnect-function-clause-error branch 2 times, most recently from 7242959 to ac759c3 Compare May 4, 2026 14:26
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@saner saner force-pushed the fix/disconnect-function-clause-error branch from ac759c3 to 1f6bd68 Compare May 4, 2026 14:28
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.

7 participants