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

Handle cancellation of TextReader/TextWriter access resiliently #111

Open
alexrp opened this issue Jan 17, 2023 · 0 comments
Open

Handle cancellation of TextReader/TextWriter access resiliently #111

alexrp opened this issue Jan 17, 2023 · 0 comments
Labels
area: io Issues related to core terminal I/O. state: approved Enhancements and tasks that have been approved.
Milestone

Comments

@alexrp
Copy link
Member

alexrp commented Jan 17, 2023

The TextReader/TextWriter and Stream properties exposed on the TerminalReader/TerminalWriter and TerminalHandle classes, respectively, are meant to be long-lived and resilient. For the Stream property, this works as expected; disposal does nothing and cancellation has no lasting effect (other than potentially losing some input/output that was scheduled).

Unfortunately, System.IO.StreamReader/System.IO.StreamWriter are not guaranteed to be in a valid state after a cancellation has occurred. This means that our properties can be rendered unusable if the user ever performs cancellation.

The main reason we have these properties is line-based input:

public string? ReadLine()
{
return TextReader.ReadLine();
}
public ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken = default)
{
return TextReader.ReadLineAsync(cancellationToken);
}

(Other than the above, these properties are not used in Cathode itself.)

The only solution I see here is to implement our own derived System.IO.TextReader/System.IO.TextWriter classes specialized for our needs. We can then do whatever we need to do to keep the state valid across cancellations.

@alexrp alexrp added type: feature state: approved Enhancements and tasks that have been approved. area: io Issues related to core terminal I/O. labels Jan 17, 2023
@alexrp alexrp added this to the v1.0 milestone Jan 17, 2023
@alexrp alexrp self-assigned this Jan 17, 2023
@alexrp alexrp modified the milestones: v1.0, v2.0 Dec 29, 2023
@alexrp alexrp removed their assignment Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: io Issues related to core terminal I/O. state: approved Enhancements and tasks that have been approved.
Development

No branches or pull requests

1 participant