Skip to content

fix(gun): compile the Gun helper modules only when :gun is present - #663

Merged
polvalente merged 2 commits into
elixir-grpc:masterfrom
palermo-git:fix/gate-gun-helper-modules
Nov 20, 2026
Merged

polvalente merged 2 commits into
elixir-grpc:masterfrom
palermo-git:fix/gate-gun-helper-modules

Conversation

@palermo-git

Copy link
Copy Markdown
Contributor

GRPC.Client.Adapters.Gun is wrapped in if Code.ensure_loaded?(:gun) (like the Mint adapter with Mint.HTTP), but its helper modules GRPC.Client.Adapters.Gun.ConnectionProcess and GRPC.Client.Adapters.Gun.StreamResponseProcess aren't. Since gun became optional (#524), a project that uses the Mint adapter without gun still compiles both, and grpc 1.1.0 prints these on every build:

warning: :gun.cancel/2 is undefined (module :gun is not available or is yet to be defined)
warning: :gun.data/4 is undefined ...
warning: :gun.open/3 is undefined ...
warning: :gun.open_unix/2 is undefined ...
warning: :gun.post/4 is undefined ...
warning: :gun.post/5 is undefined ...
warning: :gun.shutdown/1 is undefined ...
warning: :gun.stream_info/2 is undefined ...
warning: :gun.update_flow/3 is undefined ...

This gates both modules the same way as the adapter that starts them. Nothing else references them when gun is absent; the one mention in client/adapter.ex is a comment. The diff is the if plus the re-indentation mix format produces inside it: git diff -w shows four added lines, and the formatter reflowed a few lines that crossed 98 columns.

`GRPC.Client.Adapters.Gun` is wrapped in `if Code.ensure_loaded?(:gun)`
since gun became optional, but its helper modules `ConnectionProcess`
and `StreamResponseProcess` are not. A project that uses the Mint
adapter without gun compiles them anyway, and every build prints nine
`:gun.* is undefined` warnings (`:gun.open/3`, `:gun.post/4`, ...).

Gate both modules the same way as the adapter that starts them. Nothing
else references them when gun is absent. The diff is the gate plus
`mix format` re-indentation (`git diff -w` shows four lines).
@palermo-git

Copy link
Copy Markdown
Contributor Author

The one failure here, GRPC.Client.ConnectionTest "resource leaks over repeated connect/disconnect … supervisor memory bounded after garbage collection" (connection_test.exs:267, one leftover supervisor child), also fails on master: run 44733202826 today on 0f6878c and run 43453129822 on 28c2fdf. It's intermittent and unrelated to this change. Gun is present in the test environment, so both gated modules compile exactly as before. A rerun of the failed job should pass.

@polvalente

Copy link
Copy Markdown
Contributor

Could you resolve branch conflicts?

…-modules

# Conflicts:
#	grpc/lib/grpc/client/adapters/gun/connection_process.ex
@palermo-git

Copy link
Copy Markdown
Contributor Author

Conflicts resolved in 1a63fe9 by merging master. The conflict was master's newer connection_process.ex against this PR's re-indentation, so I took master's file and applied the same if Code.ensure_loaded?(:gun) gate to it, then mix format. Against master, git diff -w shows the gate plus the lines the formatter re-wrapped for the extra indent. stream_response_process.ex merged cleanly.

@polvalente
polvalente merged commit 14387e1 into elixir-grpc:master Nov 20, 2026
5 checks passed
@palermo-git
palermo-git deleted the fix/gate-gun-helper-modules branch November 20, 2026 14:00
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