Skip to content

AbstractBindTest - retry available port bind - #72

Draft
the-thing wants to merge 1 commit into
apache:2.2.Xfrom
the-thing:bind-test-fix
Draft

the-thing wants to merge 1 commit into
apache:2.2.Xfrom
the-thing:bind-test-fix

Conversation

@the-thing

Copy link
Copy Markdown
Member

Again a flaky test in 2.2.x branch.

https://github.com/apache/mina/actions/runs/35965588526/job/107523331814

In this case the issue is a time gap between org.apache.mina.util.AvailablePortFinder#getNextAvailable() and actually binding it with org.apache.mina.core.service.IoAcceptor#bind() since getNextAvailable can be made uavailable again.

The proposed change is to add a retry count in org.apache.mina.transport.AbstractBindTest#bind to try a few times. In my local environment it doesn't sometimes even happen for 1k test runs, but it happens more frequently with GitHub actions.

@the-thing the-thing self-assigned this Sep 27, 2026
@the-thing

Copy link
Copy Markdown
Member Author

Similar thing just happened in this PR's check for unrelated org.apache.mina.example.echoserver.ConnectorTest

https://github.com/apache/mina/actions/runs/36310962285/job/108596661471?pr=72

@elecharny

Copy link
Copy Markdown
Contributor

Totally agree that we need to add a retry. As the test lay be run concurrently, there is no reason to expect that the AvailablePortFinder returns a port that will be available when we try to use it.

We can't guarantee that this method will return an available port, it's a "best effort" situation.

@elecharny

Copy link
Copy Markdown
Contributor

Note that this method is used in 18 tests...

@the-thing
the-thing marked this pull request as draft September 28, 2026 04:25
@the-thing

Copy link
Copy Markdown
Member Author

I have to think what to with this. Either we explicitly use anonymous bind (I guess some tests do not do it intentionally) or just write some common code for all of them where possible.

@elecharny

Copy link
Copy Markdown
Contributor

May be using a method like:

public class AcceptorBindUtil {
    public static final int tryBind(IoAcceptor acceptor) {
        int nbTry = 10;
        
        while (true) {
            int nextAvailable = AvailablePortFinder.getNextAvailable();
            try {
                acceptor.bind( new InetSocketAddress( nextAvailable ) );
                
                return nextAvailable;
            } catch ( IOException e ) {
                nbTry--;
                
                if (nbTry == 0) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

which is called this way;

                    int nextAvailable = AcceptorBindUtil.tryBind( acceptor );

could do the trick (possibly passing the number of tries as a parameter, too)

@elecharny

elecharny commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

I'll push the suggested class and the modified test as soon as my daughter is on her way to school ;-)

(and of course if the tests pass...)

@elecharny

Copy link
Copy Markdown
Contributor

I have the tests passing with half the tests fixed, keep going

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