-
Notifications
You must be signed in to change notification settings - Fork 107
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
WebView2 hangs on reading final 0 bytes via NetFxToWinRtStreamAdapter #670
Comments
This is not a C#/WinRT issue exactly -- discussion is still going on offline about how to proceed. Seems the most appropriate fix is on the OS side of things. |
Removing blocking label as we have a workaround for this: var stream = new InMemoryRandomAccessStream();
await stream.WriteAsync(Encoding.UTF8.GetBytes($"<html><body><div>Hello, WebView2!</div></body></html>").AsBuffer()); |
Do we have any update on this? Right now the workaround is to copy all the stream content to a new stream, which is not a great solution due to performance problems. |
I hope to spend some time looking at this soon. Need to investigate whether we can remove our synchronization part of the task code if our delegates are already agile. |
FYI This only happens with CsWinRt, when the same code is executed in a UAP environment it does not hang. ### |
@j0shuams can you explain on a technical level why The documentation on WebView2's threading model states that any streams passed to webView.CoreWebView2.WebResourceRequested += async (s, e) =>
{
using var deferral = e.GetDeferral();
var url = e.Request.Uri;
var id = url.Replace("http://attachments/", "").Replace('/', '\\');
id = WebUtility.UrlDecode(path);
var path = TranslateAttachmentIdToPath(id);
if (attachment is null)
{
e.Response = webHistory.CoreWebView2.Environment.CreateWebResourceResponse(null, 404, "Not found", "");
return;
}
TaskCompletionSource<IRandomAccessStream> completion = new ();
var t = new Thread(() =>
{
var stream = File.Open(path).AsRandomAccessStream();
completion.SetResult(stream);
// no clue how long this thread should live for, but it doesn't seem to matter
});
t.IsBackground = true;
t.SetApartmentState(ApartmentState.STA);
t.Start();
var stream = await completion.Task;
e.Response = webView.CoreWebView2.Environment.CreateWebResourceResponse(stream, 200, "Found", "");
deferral.Complete();
} I'm also not aware that either of It seems that the Can you or @angelazhangmsft confirm whether this is the same issue that is being tracked internally, or if I should open this as a separate bug either in the CsWinRT repo or the WebView2Feedback repo (where a similar but not identical bug was closed after saying it was being tracked here)? |
|
@mqudsi - yes, this is being tracked internally (added internal link to the issue above). The issue you mentioned above is the same issue being tracked here. |
Thanks, @angelazhangmsft |
Fixes: dotnet#9206 microsoft/CsWinRT#670 and https://task.ms/31565319 have been marked as resolved. This PR removes the existing logic which copies the content into a memory stream, and replaces it with a call to `AsRandomAccessStream()` (`IRandomAccessStream` is still required per the `CoreWebView2` API). I tried out CSS hot reload with this change and things are working as expected. Not sure if there's a particular behavior/technique we can use to verify the validity of this change. Spoke with @Eilon regarding this, and per his recollection things were immediately hanging, and that's why this change was necessitated.
* Stop copying content stream in .NET MAUI Blazor Windows Fixes: #9206 microsoft/CsWinRT#670 and https://task.ms/31565319 have been marked as resolved. This PR removes the existing logic which copies the content into a memory stream, and replaces it with a call to `AsRandomAccessStream()` (`IRandomAccessStream` is still required per the `CoreWebView2` API). I tried out CSS hot reload with this change and things are working as expected. Not sure if there's a particular behavior/technique we can use to verify the validity of this change. Spoke with @Eilon regarding this, and per his recollection things were immediately hanging, and that's why this change was necessitated. * AutoCloseOnReadCompleteStream * Ensure old response content is closed out for hot reload * PR Feedback
Fixes: #9206 microsoft/CsWinRT#670 and https://task.ms/31565319 have been marked as resolved. This PR removes the existing logic which copies the content into a memory stream, and replaces it with a call to `AsRandomAccessStream()` (`IRandomAccessStream` is still required per the `CoreWebView2` API). I tried out CSS hot reload with this change and things are working as expected. Not sure if there's a particular behavior/technique we can use to verify the validity of this change. Spoke with @Eilon regarding this, and per his recollection things were immediately hanging, and that's why this change was necessitated.
Originally opened on WebView2:
MicrosoftEdge/WebView2Feedback#806
But may be related to the cswinrt adapter code.
Internal tracking: https://task.ms/31565319
The text was updated successfully, but these errors were encountered: