Connection Closed Error and Attempting to Reconnect
Environment
Product |
Editor for Blazor, FileManager for Blazor, FileSelect for Blazor, PdfViewer for Blazor |
Description
This article is relevant to different scenarios and Telerik Blazor components. Here are a few examples:
Editor
- Pasted images inside the Editor are discarded. They are not converted to base64 and not saved to the database.
- Pasting large images or large data always drops the Blazor app SignalR connection. The browser console shows "Attempting to reconnect" message and I have to reload the page.
- Large HTML content in the Editor restarts the Blazor app connection.
- The Editor freezes when copying and pasting long text.
- An error shows when the Editor contains a large document and the HTML string has lot of characters.
FileSelect
- The FileSelect
OnSelect
handler fails onStream
processing. - FileSelect upload scenarios break with large files. The
Stream
has no data. - Cannot
CopyToAsync
the FileSelectStream
to a newMemoryStream
. There is no error message. - Files are written to the server directory with a size of zero bytes.
- The
FileSelectFileInfo.Stream.CopyToAsync
method hangs. Execution stops and no exception is thrown. The next line in the code is never reached. I am attempting to load a JPG image into the MemoryStream.
PdfViewer
The PDF Viewer doesn't display PDF files, which are assigned to its Data
parameter, but it displays local files from the user device.
Import XSLX Files
Cannot import XSLX files which have a lot of records. It works for few records. It's a random behavior.
Error Message
The exceptions may be similar to:
Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.' Attempting to reconnect to the server...
Or:
System.Threading.Tasks.TaskCanceledException. A task was canceled.
Possible Cause
Blazor Server apps use a SignalR WebSocket to communicate between the client (browser) and server. The SignalR WebSocket has a default maximum message size of 32 KB. A large Editor Value
, FileSelect file size, or a PDFViewer Data
can exceed the maximum SignalR message size, which will close the connection and abort the current application task.
Solution
Notes
Make sure that AddServerSideBlazor()
is called only once. All configuration settings in AddHubOptions
and AddCircuitOptions
must go together with this single statement.