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

server: Fix deadlock if StopBgp is called when conn queue is full #2771

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

dawn-minion
Copy link
Contributor

Fixes a deadlock condition that can happen if StopBgp is called when the pending connection queue is full. During teardown, StopBgp calls a mgmtOp on the server goroutine which attempts to stop the goroutine accepting inbound connections, and waits for it to finish before continuing.

This connection goroutine can block if the connection queue is full, which is read by the same goroutine that processes all mgmtOps. This means that if the queue is full and the goroutine is currently blocked, then calling StopBgp will lead to a complete deadlock, as the connection goroutine will never close as it is trying to send to the queue, but the queue will not be read as the server goroutine is currently waiting for the connection goroutine to exit.

To correct this, a context has been added that gets passed to the connection goroutine. This is then checked in a new select statement on the connection queue which gets cancelled by tcpListener.Close() ensuring the goroutine exits correctly even if the queue is full.

Fixes a deadlock condition that can happen if StopBgp is called when the
pending connection queue is full. During teardown, StopBgp calls a
mgmtOp on the server goroutine which attempts to stop the goroutine
accepting inbound connections, and waits for it to finish before
continuing.

This connection goroutine can block if the connection queue is full,
which is read by the same goroutine that processes all mgmtOps. This
means that if the queue is full and the goroutine is currently blocked,
then calling StopBgp will lead to a complete deadlock, as the connection
goroutine will never close as it is trying to send to the queue, but the
queue will not be read as the server goroutine is currently waiting for
the connection goroutine to exit.

To correct this, a context has been added that gets passed to the
connection goroutine. This is then checked in a new select statement on
the connection queue which gets cancelled by tcpListener.Close() ensuring
the goroutine exits correctly even if the queue is full.
@fujita fujita merged commit 87e5b81 into osrg:master Mar 2, 2024
39 checks passed
@fujita
Copy link
Member

fujita commented Mar 2, 2024

Thanks!

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