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

Provide the remaining buffer when the NIOAsyncSequenceProducer termin… #3111

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FranzBusch
Copy link
Member

…ates

Motivation

Our NIOAsyncChannel abstractions is running into crashes in the bootstraps and multiplexer when a NIOAsyncChannel is buffered inside an async stream and the consuming task gets cancelled.

Modification

This PR modifies the NIOAsyncSequenceProducer to hand over the remaining elements once it is finished to didTerminate to allow the user to run any manual clean up such as closing the underling channel of a NIOAsyncChannel.

Result

A path forward to avoid the crashes we are seeing.

[One line description of your change]

Motivation:

[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]

Modifications:

[Describe the modifications you've done.]

Result:

[After your change, what will change.]

…ates

# Motivation

Our `NIOAsyncChannel` abstractions is running into crashes in the bootstraps and multiplexer when a `NIOAsyncChannel` is buffered inside an async stream and the consuming task gets cancelled.

# Modification

This PR modifies the `NIOAsyncSequenceProducer` to hand over the remaining elements once it is finished to `didTerminate` to allow the user to run any manual clean up such as closing the underling channel of a `NIOAsyncChannel`.

# Result

A path forward to avoid the crashes we are seeing.
/// - The consuming `Task` is cancelled (e.g. `for await let element in`).
/// - The source finished and all remaining buffered elements have been consumed.
///
/// - Note: This is guaranteed to be called _exactly_ once.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update the note on the other didTerminate to indicate that it is no longer called, but if no implementation of didTerminate(remainingBuffer:) is provided this will be called from there in the default implementation.

/// - The source finished and all remaining buffered elements have been consumed.
///
/// - Note: This is guaranteed to be called _exactly_ once.
func didTerminate(remainingBuffer: some Collection<Any>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to box the elements? Why isn't this just some Collection?

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