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

fix: infinite loop when connection is aborted before being accepted #1164

Merged
merged 5 commits into from
Aug 7, 2024

Conversation

diegomrsantos
Copy link
Contributor

@diegomrsantos diegomrsantos commented Aug 5, 2024

self.acceptFuts[index] = self.servers[index].accept() wasn't being called when there was an error.

@diegomrsantos diegomrsantos changed the title reproduce accept bug fix: infinite loop when connection is aborted before being accepted Aug 5, 2024
@diegomrsantos diegomrsantos marked this pull request as ready for review August 5, 2024 17:08
Copy link
Collaborator

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you very much for fixing this.

@kaiserd kaiserd merged commit cde5ed7 into master Aug 7, 2024
14 checks passed
@kaiserd kaiserd deleted the aceept-bug branch August 7, 2024 18:54
self.acceptFuts = self.servers.mapIt(it.accept())

let
finished =
try:
# Waits for any one of these futures to complete, indicating that a new connection has been accepted on one of the servers.
await one(self.acceptFuts)
except ValueError:
raise (ref TcpTransportError)(msg: "No listeners configured")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should not rely on chronos one() function to understand that length of self.acceptFuts == 0, you should establish your own check and in case of ValueError returned from one() call you could raise assertion.

self.acceptFuts = self.servers.mapIt(it.accept())

let
finished =
try:
# Waits for any one of these futures to complete, indicating that a new connection has been accepted on one of the servers.
Copy link
Contributor

Choose a reason for hiding this comment

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

This await call missing Cancellation handler. Because you are using combinator one() which does not perform any cancellation on passed Futures, so in case of cancellation its possible that all it.accept() futures will be left unattended.

except common.TransportError as exc: # Needed for chronos 4.0.0 support
raise (ref TcpTransportError)(msg: exc.msg, parent: exc)
except CancelledError as exc:
raise exc
Copy link
Contributor

Choose a reason for hiding this comment

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

In this handler you do not catch CatchableError anymore, so there is no need to save this default Cancellation handler. Of course in this specific case you should do something with acceptFuts array which could be left unattended.

diegomrsantos added a commit that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

3 participants