Skip to content

fix(diam): return a nil listener or address on error - #73

Merged
gomaja merged 1 commit into
mainfrom
fix/i68-listen-nil
Oct 10, 2026
Merged

gomaja merged 1 commit into
mainfrom
fix/i68-listen-nil

Conversation

@gomaja

@gomaja gomaja commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

When the SCTP listen fails, diam.MultistreamListen returned sctpListener{(*sctp.Listener)(nil)} together with the error, and diam.Listen turned the typed nil *sctp.Listener into a non-nil net.Listener. A caller that tests the listener before the error, or defers l.Close(), took the wrong branch or dereferenced nil. An audit of the dial and listen paths found the same pattern in resolveAddress, which could return a typed nil *sctp.Addr or *net.TCPAddr with its error.

All three now return a nil interface with the error, as net.Listen does.

Tests

TestListenResult covers Listen and MultistreamListen on sctp, sctp4, sctp6, tcp, tcp4 and tcp6, with three cases each:

  • a bind error on an address not on this host (EADDRNOTAVAIL);
  • an invalid port;
  • a successful listen.

TestResolveAddressError and TestResolveAddressSuccess cover resolveAddress.

Before the fix the tests failed with:

  • "listen returned non-nil listener (*sctp.Listener)(nil)";
  • "diam.sctpListener{Listener:(*sctp.Listener)(nil)}";
  • "resolveAddress returned non-nil address".

Four mutations restoring the old returns were each caught.

Validation

go build ./..., go test ./... -count=1, go test -race ./diam/... -count=1, go vet ./..., staticcheck ./... and golangci-lint run ./... all pass, and gofmt -l . is empty. The examples/middleware build, vet and test pass.

Fixes #68


Summary by cubic

Fixes SCTP listen and address resolution returning typed nil values on error. Listen, MultistreamListen, and resolveAddress now return a nil interface with the error, matching net.Listen, so callers that test the listener before the error or defer Close() no longer encounter a non-nil interface.

Tests added for both listen functions across all SCTP and TCP networks, covering bind errors, invalid ports, and successful listens, plus resolveAddress success and error cases.

Written for commit d6cc812. Summary will update on new commits.

View guided diff Turn on auto-fix

Copilot AI balanced review requested due to automatic review settings October 10, 2026 00:22
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 109f6aa1-eccc-4f6e-b571-bfb171a50843

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

When the SCTP listen failed, MultistreamListen returned
sctpListener{(*sctp.Listener)(nil)} with the error, and Listen converted
the typed nil *sctp.Listener into a non-nil net.Listener. A caller that
tested the listener before the error, or deferred its Close, took the
wrong branch or dereferenced nil. resolveAddress did the same with a
typed nil *sctp.Addr or *net.TCPAddr.

All three now return a nil interface with the error, as net.Listen and
net.ResolveTCPAddr do. Tests cover a bind error (EADDRNOTAVAIL), an
invalid port and a successful listen on every sctp and tcp network for
both listen functions, and resolveAddress's error and success results.

Fixes #68
@gomaja
gomaja force-pushed the fix/i68-listen-nil branch from 6074e26 to d6cc812 Compare October 10, 2026 01:10
@gomaja

gomaja commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

The lint failure is not from this change: staticcheck 2026.2.1 cannot read the export data of Go 1.27.2, the stable release CI now installs, so it stopped before analysing any package. Under Go 1.27.2, a staticcheck built from go-tools master (f1838cc3, which carries the fix) and golangci-lint both report no issues on this branch. The workflow pin is updated in a separate change.

@gomaja
gomaja merged commit 8f1f77d into main Oct 10, 2026
16 of 17 checks passed
@gomaja
gomaja deleted the fix/i68-listen-nil branch October 10, 2026 01:14
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.

MultistreamListen and Listen return a non-nil listener with an error when the SCTP listen fails

2 participants