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

[Blazor WebAssembly] Support for Cancelling HTTP Requests by Diposing Response Stream #64225

Closed
tpeczek opened this issue Jan 24, 2022 · 3 comments · Fixed by #64285
Closed
Assignees
Labels
arch-wasm WebAssembly architecture area-System.Net.Http
Milestone

Comments

@tpeczek
Copy link

tpeczek commented Jan 24, 2022

When working with ReadableStream in JavaScript, one can call ReadableStreamDefaultReader.cancel() which will triger request cancellation if the server is still streaming.

In Blazor WebAssembly this is currently not possible, as WasmHttpReadStream uses the reader only to advance the ReadableStream and on dispose only diposes the references to JavaScript objects. It looks like this functionality could be achieved by adding call to cancel() in WasmHttpReadStream.Dispose.

private sealed class WasmHttpReadStream : Stream
{
    ...

    protected override void Dispose(bool disposing)
    {
        if (!(_reader is null))
        {
            _reader.Invoke("cancel");
        }

        _reader?.Dispose();
        _status?.Dispose();
    }

    ...
}

Such a change would be a great improvement for scenarios like consuming async streams coming from servers.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net.Http untriaged New issue has not been triaged by the area owner labels Jan 24, 2022
@ghost
Copy link

ghost commented Jan 24, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

When working with ReadableStream in JavaScript, one can call ReadableStreamDefaultReader.cancel() which will triger request cancellation if the server is still streaming.

In Blazor WebAssembly this is currently not possible, as WasmHttpReadStream uses the reader only to advance the ReadableStream and on dispose only diposes the references to JavaScript objects. It looks like this functionality could be achieved by adding call to cancel() in WasmHttpReadStream.Dispose.

private sealed class WasmHttpReadStream : Stream
{
    ...

    protected override void Dispose(bool disposing)
    {
        if (!(_reader is null))
        {
            _reader.Invoke("cancel");
        }

        _reader?.Dispose();
        _status?.Dispose();
    }

    ...
}

Such a change would be a great improvement for scenarios like consuming async streams coming from servers.

Author: tpeczek
Assignees: -
Labels:

area-System.Net.Http, untriaged

Milestone: -

@ManickaP ManickaP added the arch-wasm WebAssembly architecture label Jan 25, 2022
@ghost
Copy link

ghost commented Jan 25, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

When working with ReadableStream in JavaScript, one can call ReadableStreamDefaultReader.cancel() which will triger request cancellation if the server is still streaming.

In Blazor WebAssembly this is currently not possible, as WasmHttpReadStream uses the reader only to advance the ReadableStream and on dispose only diposes the references to JavaScript objects. It looks like this functionality could be achieved by adding call to cancel() in WasmHttpReadStream.Dispose.

private sealed class WasmHttpReadStream : Stream
{
    ...

    protected override void Dispose(bool disposing)
    {
        if (!(_reader is null))
        {
            _reader.Invoke("cancel");
        }

        _reader?.Dispose();
        _status?.Dispose();
    }

    ...
}

Such a change would be a great improvement for scenarios like consuming async streams coming from servers.

Author: tpeczek
Assignees: -
Labels:

arch-wasm, area-System.Net.Http, untriaged

Milestone: -

@lewing lewing added this to the 7.0.0 milestone Jan 25, 2022
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Jan 25, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 25, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 29, 2022
@gilm0079
Copy link

I'm experiencing the same issue. I probably posted in the wrong channel. I was advised to link it here. Would someone consider this fix for .net 6? I'm working on a blazor wasm production app and it would be helpful if user initiated cancels on token sources aborted http connections to the server api so that the asp.net core api treats the RequestAborted as a cancelled token and I can also cascade up cancellation of pending server operations. Thanks.

mono/mono#21436

@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-System.Net.Http
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants