-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Blazor Server UploadFile Throws "System.InvalidOperationException: Reading is not allowed after reader was completed." #52723
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
The only workaround I managed to find is simply restarting the upload for this individual file like this:
The exception will still occur every 5-70 files, now you just don't care about it. |
I am seeing the same kind of error in a .NET8 Blazor Server App. The test file I am using is around 170MB and it fails every time. CODE EXAMPLE: const int kb = 1024;
const int mb = 1024 * kb;
const long gb = 1024 * mb;
string destinationFullPath = Path.Combine(savePath, inputFile.Name);
byte[] buffer = System.Buffers.ArrayPool<byte>.Shared.Rent(mb);
try
{
await using FileStream destination = new(destinationFullPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, mb, FileOptions.Asynchronous);
await using Stream readStream = inputFile.OpenReadStream(2 * gb);
long totalBytesRead = 0;
long fileSize = inputFile.Size;
while (readStream.CanRead)
{
int bytesRead = await readStream.ReadAsync(buffer.AsMemory(0, mb));
if (bytesRead <= 0) break;
totalBytesRead += bytesRead;
int newProgress = (int)(100 * totalBytesRead / fileSize);
await destination.WriteAsync(buffer.AsMemory(0, bytesRead));
if (newProgress != ProgressValue)
{
ProgressValue = newProgress;
// Fire the event of OnProgress to notify the client about progress so far
OnProgress?.Invoke(newProgress);
}
}
logger.Info($"Downloaded file from user to: {destinationFullPath}");
}
catch (Exception ex)
{
logger.Error(ex, $"Failure saving file submitted by user to: {destinationFullPath}");
}
finally
{
System.Buffers.ArrayPool<byte>.Shared.Return(buffer);
} ERROR EXAMPLE:
|
I believe this issue is a duplicate of #53951 Which is related to #47301 The workaround is to find your SignalR hub options and change These things should be decoupled. SignalR settings should not break file transfers and vice versa. WORKAROUND:
|
Describe the bug
I use Blazor Server .NET 7.0.
Some of the users have difficulties uploading files (when I myself don't: I've uploaded over 1000 files at this point and never had an issue). After uploading some amount of files, upload silently stops, they even can click on the InputFile again, pick new files, and the upload will start again (and then stop by the same reason). Sometimes bug happens after 20 uploads, sometimes after 8, sometimes never, the amount is random.
In the end, I managed to get their chrome console and there is
System.InvalidOperationException: Reading is not allowed after reader was completed.
error.All that time, there was no logs on the server (probably because of my appsettings?).
For the most time, files is around 10MB.
Deployed on Ubuntu with Nginx.
Websocked connection is established, even when the error occurs.
I had an idea that it's somehow connected to the MacBook usage, but one Windows user told that he has the same behaviour.
Code I use:
Exception
If there is any more information that is needed please feel free to ask.
The text was updated successfully, but these errors were encountered: