Skip to content
This repository was archived by the owner on Aug 16, 2026. It is now read-only.
This repository was archived by the owner on Aug 16, 2026. It is now read-only.

Handle cancellation of TextReader/TextWriter access resiliently #111

Description

@alexrp

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: ioIssues related to core terminal I/O.state: approvedEnhancements and tasks that have been approved.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions