-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,40 +230,43 @@ method accept*(self: TcpTransport): Future[Connection] = | |
raise newTransportClosedError() | ||
|
||
if self.acceptFuts.len <= 0: | ||
# Holds futures representing ongoing accept calls on multiple servers. | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should not rely on chronos |
||
|
||
index = self.acceptFuts.find(finished) | ||
transp = | ||
try: | ||
await finished | ||
except TransportTooManyError as exc: | ||
debug "Too many files opened", exc = exc.msg | ||
return nil | ||
except TransportAbortedError as exc: | ||
debug "Connection aborted", exc = exc.msg | ||
return nil | ||
except TransportUseClosedError as exc: | ||
raise newTransportClosedError(exc) | ||
except TransportOsError as exc: | ||
raise (ref TcpTransportError)(msg: exc.msg, parent: exc) | ||
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 | ||
|
||
# A new connection has been accepted. The corresponding server should immediately start accepting another connection. | ||
# Thus we replace the completed future with a new one by calling accept on the same server again. | ||
self.acceptFuts[index] = self.servers[index].accept() | ||
let transp = | ||
try: | ||
await finished | ||
except TransportTooManyError as exc: | ||
debug "Too many files opened", exc = exc.msg | ||
return nil | ||
except TransportAbortedError as exc: | ||
debug "Connection aborted", exc = exc.msg | ||
return nil | ||
except TransportUseClosedError as exc: | ||
raise newTransportClosedError(exc) | ||
except TransportOsError as exc: | ||
raise (ref TcpTransportError)(msg: exc.msg, parent: exc) | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this handler you do not catch |
||
|
||
if not self.running: # Stopped while waiting | ||
await transp.closeWait() | ||
raise newTransportClosedError() | ||
|
||
self.acceptFuts[index] = self.servers[index].accept() | ||
|
||
let remote = | ||
try: | ||
transp.remoteAddress | ||
|
There was a problem hiding this comment.
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 combinatorone()
which does not perform any cancellation on passed Futures, so in case of cancellation its possible that allit.accept()
futures will be left unattended.