Skip to content

PullFromJSDataStream should dispose IJSStreamReference internally #62140

Open
@ivanjx

Description

@ivanjx

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

to keep my code works across platforms (both native and web) with as minimal effor as possible, i only accept Stream in my business logic to read files from the system. aside from using the InputFile, sometimes i also pass javascript's File object back to the c# side and cast it as IJSStreamReference.

while debugging, i found out that opening a read stream that way gives me PullFromJSDataStream instead of BrowserFileStream. correct me if im wrong here but after reading the code for some time, both implementations contains internal IJSStreamReference but only BrowserFileStream disposes it correctly.

Describe the solution you'd like

as implemented by BrowserFileStream:

protected override void Dispose(bool disposing)
    {
        if (_isDisposed)
        {
            return;
        }

        _openReadStreamCts.Cancel();
        _copyFileDataCts?.Cancel();

        // If the browser connection is still live, notify the JS side that it's free to release the Blob
        // and reclaim the memory. If the browser connection is already gone, there's no way for the
        // notification to get through, but we don't want to fail the .NET-side disposal process for this.
        try
        {
            _ = _jsStreamReference?.DisposeAsync().Preserve();
        }
        catch
        {
        }

        _isDisposed = true;

        base.Dispose(disposing);
    }

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions