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

NIOAsyncChannel can hit an assertion failure in NIOAsyncWriter if the listening channel closes while activating an accepted connection #2813

Open
glbrntt opened this issue Jul 26, 2024 · 1 comment

Comments

@glbrntt
Copy link
Contributor

glbrntt commented Jul 26, 2024

If the listening channel is shutting down then accepted connections which haven't yet been referenced by the caller will be dropped. If the as-yet-unreferenced accepted connections have been activated (channelActive) has fired the channel will drop its ref to the outbound writer. As the ref count drops to zero we'll the assertion failure in NIOAsyncWriter.

glbrntt added a commit to glbrntt/grpc-swift that referenced this issue Jul 26, 2024
Motivation:

The h2 transport tests cancel the task group running them when the test
has completed. Cancelling the server makes apple/swift-nio#2813
more likely to occur.

Modifications:

- Tell the server to stop listening and let the test stop gracefully

Result:

Fewer runtime issues
glbrntt added a commit to grpc/grpc-swift that referenced this issue Jul 26, 2024
Motivation:

The h2 transport tests cancel the task group running them when the test
has completed. Cancelling the server makes apple/swift-nio#2813
more likely to occur.

Modifications:

- Tell the server to stop listening and let the test stop gracefully

Result:

Fewer runtime issues
@FranzBusch
Copy link
Member

Thanks for opening this. The problem is similar to what we see in H2 when the consuming task of the inbound streams sequence gets cancelled. Currently both async sequences in question are dropping all buffered elements on the ground on cancellation. Now in both cases the element type can by a NIOAsyncSequence producer and that will lead to us hitting the precondition of the writer.

The fundamental issue that we are having here is that those async sequence are our place where we hand off the element from the EL to Swift Concurrency. Two solutions that come to mind:

  • We don't drop the buffer on cancellation but just tell whatever produces the elements to stop and continue to hand the elements out
  • We find a way to gracefully drop all the elements on the ground. Now the complicated part here is that the element type is generic and a user could return anything from the channel initialisers.

clintonpi pushed a commit to clintonpi/grpc-swift that referenced this issue Jul 29, 2024
Motivation:

The h2 transport tests cancel the task group running them when the test
has completed. Cancelling the server makes apple/swift-nio#2813
more likely to occur.

Modifications:

- Tell the server to stop listening and let the test stop gracefully

Result:

Fewer runtime issues
glbrntt added a commit to grpc/grpc-swift-nio-transport that referenced this issue Sep 20, 2024
Motivation:

The h2 transport tests cancel the task group running them when the test
has completed. Cancelling the server makes apple/swift-nio#2813
more likely to occur.

Modifications:

- Tell the server to stop listening and let the test stop gracefully

Result:

Fewer runtime issues
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

No branches or pull requests

2 participants