Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat._bind_socket continually retries on success #430

Closed
mdickinson opened this issue Sep 12, 2019 · 2 comments · Fixed by #431
Closed

Heartbeat._bind_socket continually retries on success #430

mdickinson opened this issue Sep 12, 2019 · 2 comments · Fixed by #431

Comments

@mdickinson
Copy link
Contributor

I think there's a logic bug in the implementation of Heartbeat._bind_socket. The current code looks like this:

        max_attempts = 1 if self.original_port else 100
        for attempt in range(max_attempts):
            try:
                self._try_bind_socket()
            except zmq.ZMQError as ze:
                if attempt == max_attempts - 1:
                    raise
                # Raise if we have any error not related to socket binding
                if ze.errno != errno.EADDRINUSE and ze.errno != win_in_use:
                    raise
                # Raise if we have any error not related to socket binding
                if self.original_port == 0:
                    self.pick_port()
                else:
                    raise

If self._try_bind_socket fails with an exception, we try again; that part makes sense to me. But if self._try_bind_socket succeeds ..., we also enter the next iteration of the for loop and try again. I think there should be a return or a break at that point.

When I test this on my machine (in the case where self.original_port is False), the effect is that 50 different ports are tried, twice each: the first attempt of each pair succeeds, and the second one fails (because the port is already in use). The end result is that the run method is abandoned and the heartbeat isn't ever properly started.

Changing 100 to 101 (or 99) allows the heartbeat to start. That's obviously not the right fix. :-)

@mdickinson
Copy link
Contributor Author

Fix in #431, but I just noticed that @pauldmccarthy also provided a fix in #429, and that fix also looks good to me. FWIW, the #431 fix has a regression test. Not sure what the easiest way forward is here: I can patch that regression test into #429 if that makes sense.

@pauldmccarthy
Copy link
Contributor

I'm also happy for #429 to be closed - given that you've added a test, yours is better :)

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 a pull request may close this issue.

2 participants