Closed rocketraman closed 4 years ago
As I noted in Slack, these errors seem to occur when the client has disconnected while there are active connections.
This wasn't required in Embed.IO v2, but in v3, it looks like I need to use a pattern like this to catch these errors and ignore them:
try {
...
var responseStream = HttpContext.OpenResponseStream();
await resultStream.CopyToAsync(responseStream);
}
catch (BusinessException)
{
throw HttpException ...
}
catch (IOException e)
{
// ignore it, client probably disconnected or other network problem, client will retry if necessary
// we can re-throw an InternalServerError just in case this is something else, but if the client is gone,
// this throws an error itself, so ignore that too
try
{
throw HttpException.InternalServerError(data: ...);
}
catch (Exception)
{
// ignore
}
}
Can you post the code that you use for EmbedIO v2?
Usually, the ResponseStream is handling the IOException
here (https://github.com/unosquare/embedio/blob/master/src/EmbedIO/Net/Internal/ResponseStream.cs#L158).
Same code without that extra catch block.
The code you pointed out only handles IOException inside a Dispose
call. As you can see from the stack I posted, this exception is occurring outside of that call -- note the two EmbedIO.Net.Internal.ResponseStream
frames here:
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at EmbedIO.Net.Internal.ResponseStream.InternalWrite(Byte[] buffer, Int32 offset, Int32 count)
at EmbedIO.Net.Internal.ResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Compression.DeflateStream.PurgeBuffers(Boolean disposing)
at System.IO.Compression.DeflateStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
I found the reason for the change in this behavior.
There is a setting, WebServer.Listener.IgnoreWriteExceptions
, to ignore any Write exception from the ResponseStream
. EmbedIO v2 by default set this flag to true, but v3 doesn't.
Your solution is to set this flag to true before starting the WebServer.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Thanks for the information about WebServer.Listener.IgnoreWriteException
.
Describe the bug I upgraded to Embed.IO 3.1.1 from 2.9.2. When running a test in which I interrupt the client, or a stress test via
siege
for a controller that returns a stream of data, Embed.IO always writes errors like this:To Reproduce Steps to reproduce the behavior:
The test does not even have to be cancelled early for these errors to show up. I don't know what Siege is doing, but the same test with Embed.IO 2.x does not produce these errors. On the client side siege does not report any errors, so this appears to be harmless, but annoying.
Expected behavior No errors in the logs.
Desktop (please complete the following information):