Skip to content

Blazor Server: Deadlock when JavaScript-Interop is called directly after StateHasChanged() #10889

@DNF-SaS

Description

@DNF-SaS

Consider the following code-snippet:

this.StateHasChanged(); // [1]
this.Logger.Debug("after StateHasChanged()"); // [2]
// [2/3]
using (var fileReaderStream = await fileRef.OpenReadAsync()) // [3] JS-Interop is behind this call
{ ... }

Running the code in this order (first StateHasChanged() then something with JS-Interop) causes Blazor Server to deadlock pretty often.
Looking at the log-output, the order is different than the code.
If Task.Delay(2000) is added at position [2/3], everything is fine.
(sorry for the vague description, but it's really hard to get grip on this issue and to explain it precisely)

[2] [11:54:16 DBG] after StateHasChanged() - OnFileSelectedAsync @ Uploader.razor:249
[1] [11:54:16 DBG] Received hub invocation: InvocationMessage { InvocationId: "", Target: "OnRenderCompleted", Arguments: [ 5,  ], StreamIds: [  ] }.
[11:54:16 DBG] Received confirmation for batch 5.
[11:54:16 DBG] Completing batch 5 without error.
[3] [11:54:16 DBG] Received hub invocation: InvocationMessage { InvocationId: "", Target: "BeginInvokeDotNetFromJS",

Is this a known problem (maybe related to #9901 ) / already filed issue?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions