Skip to content

DragNDrop SSB Race Condition #71

@srowan

Description

@srowan
  • Server side blazor
  • Similar code to the dragndrop example
  • Getting the following error randomly on refresh (about 30%-50% of the time):
      Unhandled exception rendering component: Could not find 'FileReaderComponent' in 'window'.
Error: Could not find 'FileReaderComponent' in 'window'.

The error occurs on: RegisterDropEventsAsync(); :

       protected override async Task OnAfterRenderAsync()
        {
            labelFilesReference = fileReaderService.CreateReference(labelElement);
            await labelFilesReference.RegisterDropEventsAsync();
        }

I do have InitializeOnFirstCall enabled, but I also tried this as well:

       protected override async Task OnAfterRenderAsync()
        {
            await fileReaderService.EnsureInitializedAsync();
            labelFilesReference = fileReaderService.CreateReference(labelElement);
            await labelFilesReference.RegisterDropEventsAsync();
        }

... and still received the error (same frequency). Adding Task.Delay did not help.

Retrying when it fails fixes the issue, which I think is probably evidence that there is a race condition here (which could mean the problem can only be replicated at very low latency e.g. local development).

This works:

        protected override async Task OnAfterRenderAsync()
        {
            labelFilesReference = fileReaderService.CreateReference(labelElement);
            try
            {
                await labelFilesReference.RegisterDropEventsAsync();
            }
            catch (JSException ex)
            when (ex.Message.Contains("Could not find 'FileReaderComponent' in 'window'"))
            {
                // failed race condition, just try again
                await labelFilesReference.RegisterDropEventsAsync();
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions