-
Notifications
You must be signed in to change notification settings - Fork 852
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
System.InvalidOperationException: Reading is already in progress. #2655
Comments
What does the implementation of |
internal class Decorator : Stream
{
private readonly Stream innerStream;
public long BytesWritten { get; private set; }
public override bool CanRead => false;
public override bool CanSeek => false;
public override bool CanWrite => innerStream.CanWrite;
public override long Length => innerStream.Length;
public override long Position { get => innerStream.Position; set => throw new NotSupportedException(); }
public Decorator(Stream innerStream) => this.innerStream = innerStream;
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
BytesWritten += buffer.Length;
return innerStream.WriteAsync(buffer, cancellationToken);
}
public override Task FlushAsync(CancellationToken cancellationToken) => innerStream.FlushAsync(cancellationToken);
public override void Flush() => throw new NotSupportedException();
public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => throw new NotSupportedException();
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => throw new NotSupportedException();
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => throw new NotSupportedException();
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
public override void SetLength(long value) => throw new NotSupportedException();
} In case of reproduction, unfortunately I am not able to do it. This error occurs on once in a million requests (literally). |
Are you able to collect the full stack trace for the exception ( |
I am not sure where to do it. This exception was thrown either before or after my pipeline, above middelware was mentioned only because it works with request body. Exception was not thrown there or in any of my middelwares (I assume that because there are no other logs that should be produced by my application in such case). Source context of that error is: BTW |
From the message you've shared it looked like it may have only been including the top-most exception information, but looking into dotnet/aspnetcore#17840 more, that may just be all the info that's available at the time. This sounds like a bug in ASP.NET Core, not much we can do about it in YARP. YARP itself isn't using the request body pipe directly, and from your description neither are you. |
@MihaZupan could you report issue in appropriate repo of ASP.NET Core? |
Do you mean dotnet/aspnetcore#17840? |
Hi, we have encountered below exception in our microservice serving as reverse proxy:
I have found several issues related to this topic:
The last one is suggesting that the reason may be invalid handling of reading request body. In our scenario there were no such operations (also buffering was not enabled). The only manipulation on body was as follows:
LogRequest
is designed to log incoming request with optional logging of body. This option is however currently disabled. The only action taken iscontext.Response.Body = originalBodyStream;
. What could be a cause of above exception and how could we prevent it?We are currently using
Yarp.ReverseProxy
in2.0.1
version (not updated because of #2631).The text was updated successfully, but these errors were encountered: