Skip to content

test: make RemotingSpec bind retry match the classic Netty BindException - #3551

Open
pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:remoting-spec-bind-retry
Open

pjfanning wants to merge 1 commit into
apache:mainfrom
pjfanning:remoting-spec-bind-retry

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

RemotingSpec "allow other system to connect even if it's not there at first" still fails intermittently in CI with java.net.BindException: Address already in use when the port from temporaryServerAddress() is taken before the new ActorSystem binds (seen again on #3549, Check / Tests (scala213)).

The retry in selectionAndBind only fires when the exception message contains "Failed to bind", but classic Netty remoting rethrows the raw BindException from Remoting.start, so the guard never matched and the retry added in #3015 was effectively dead code on this path. That string only exists in the Artery TCP transport.

Modification

  • Add an isBindFailure helper that walks the cause chain and matches on java.net.BindException (keeping the "Failed to bind" message check for other transports), and use it as the retry guard in selectionAndBind.
  • Add a directional test that starts an ActorSystem on a port already held by a ServerSocket and asserts the thrown exception is recognized by isBindFailure (and that an unrelated exception is not). The old string guard returns false for this exception.

Result

The lazy-connect tests retry on a fresh port when the temporary port is already in use instead of failing the suite.

Tests

  • scalafmt remote/src/test/scala/org/apache/pekko/remote/classic/RemotingSpec.scala
  • sbt "remote/testOnly org.apache.pekko.remote.classic.RemotingSpec" — 23 tests, all passing (includes the new test)
  • git diff --check

References

Refs #1679, Refs #3015 - port race in RemotingSpec lazy-connect tests

Motivation:
RemotingSpec "allow other system to connect even if it's not there at
first" still fails intermittently in CI with
`java.net.BindException: Address already in use` when the port from
temporaryServerAddress() is taken before the new ActorSystem binds.
The retry in selectionAndBind only fires when the exception message
contains "Failed to bind", but classic Netty remoting rethrows the raw
BindException from ActorSystem startup, so the guard never matched and
the retry added in apache#3015 was dead code on this path.

Modification:
Add an isBindFailure helper that walks the cause chain and matches on
java.net.BindException (keeping the "Failed to bind" message check for
other transports), and use it as the retry guard in selectionAndBind.
Add a directional test that starts an ActorSystem on a port already
held by a ServerSocket and asserts the thrown exception is recognized
by isBindFailure.

Result:
The lazy-connect tests retry on a fresh port when the temporary port
is already in use instead of failing the suite.

Tests:
- scalafmt remote/src/test/scala/org/apache/pekko/remote/classic/RemotingSpec.scala
- sbt "remote/testOnly org.apache.pekko.remote.classic.RemotingSpec" (23 tests, all passing)
- git diff --check

References:
Refs apache#1679, Refs apache#3015 - port race in RemotingSpec lazy-connect tests
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.

1 participant