Skip to content
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

Writing to the response body is invalid for responses with status code 204 #306

Closed
gregoks opened this issue Jul 29, 2019 · 13 comments
Closed
Labels

Comments

@gregoks
Copy link

gregoks commented Jul 29, 2019

Hi,

Many times I see the following error when I use wiremock:

"HttpStatusCode set to 500 System.InvalidOperationException: Writing to the response body is invalid for responses with status code 204. at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowWritingToResponseBodyNotSupported() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WriteAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at WireMock.Owin.Mappers.OwinResponseMapper.MapAsync(ResponseMessage responseMessage, HttpResponse response) at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternal(HttpContext ctx)"

it comes from the following class:

WireMock.Owin.GlobalExceptionMiddleware+d__7.MoveNext

I thought that perhaps I'm trying to add mapping with response content for http status 204 but I havent found anything like that.

Do you have any idea about this sort of error?

Thanks,

Greg

@StefH
Copy link
Collaborator

StefH commented Jul 30, 2019

If possible, please provide the mappings you use.

@gregoks
Copy link
Author

gregoks commented Jul 31, 2019

Thats the thing, I dont see that it's related to a mapping that I have added. is it possible?
I'll try to increase the log level to see if I can add more information.

@StefH
Copy link
Collaborator

StefH commented Jul 31, 2019

Or provide a demo project ?

@gregoks
Copy link
Author

gregoks commented Aug 7, 2019

@StefH just to update, I have tried to make my logs to be "Debug". still havent really figured out the issue, but I saw this error one time:

  • HttpStatusCode set to 500 Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate. at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.PumpAsync() at System.IO.Pipelines.PipeCompletion.ThrowLatchedException() at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) at System.IO.Pipelines.Pipe.GetReadAsyncResult() at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.CopyToAsync(Stream destination, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.CopyToAsyncInternal(Stream destination, CancellationToken cancellationToken) at WireMock.Util.BodyParser.ReadBytesAsync(Stream stream) at WireMock.Util.BodyParser.Parse(Stream stream, String contentType) at WireMock.Owin.Mappers.OwinRequestMapper.MapAsync(HttpRequest request) at WireMock.Owin.WireMockMiddleware.InvokeInternal(HttpContext ctx) at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternal(HttpContext ctx)

and I would like to ask if you could create pre-release version with the following change in the WireMockMiddleware class:

In many cases I see the following error without any exception stack trace:

"HttpStatusCode set to 500"

because you error message without the exception in this line:

_options.Logger.Error("HttpStatusCode set to 500");

The error is very general, could add the exception itself to the error?
Or even if you could add the problematic mapping to the log message, that would be even better!

Thanks,

Greg

@gregoks
Copy link
Author

gregoks commented Aug 7, 2019

Just to clarify, Im using wiremock as an mocking infra in a company I work for. Currently I have around 20 mocks set up on different ports and automation nightlies are running at the same time, adding miltiple mappings and sometimes the errors that Ive mentioned happen so without the logging, its hard to understand which mapping causes the error.

@StefH
Copy link
Collaborator

StefH commented Aug 7, 2019

You mean this line?

_options.Logger.Error("HttpStatusCode set to 500");

@StefH
Copy link
Collaborator

StefH commented Aug 7, 2019

Can you install WireMock.Net.1.0.27-ci-11567.nupkg?

This version contains more logging. e423a99

@gregoks
Copy link
Author

gregoks commented Aug 8, 2019

You mean this line?

_options.Logger.Error("HttpStatusCode set to 500");

yes exactly. It would be great if you could add the exception to the error message or perhaps even the mapping that caused it..

@StefH
Copy link
Collaborator

StefH commented Aug 8, 2019

Can you install and try WireMock.Net.1.0.27-ci-11567.nupkg from MyGet?

@gregoks
Copy link
Author

gregoks commented Aug 8, 2019

Can you install WireMock.Net.1.0.27-ci-11567.nupkg?

This version contains more logging. e423a99

sure, ill try and let you know.

@gregoks
Copy link
Author

gregoks commented Aug 8, 2019

I have tried WireMock.Net.1.0.27-ci-11567 and the logs that you have added help! I saw the reason for the error, it was a mapping that led to service that took really long time to respond.

@StefH
Copy link
Collaborator

StefH commented Aug 8, 2019

Good to hear.

Also check if #308 is still happening, or maybe this is also fixed.

@StefH
Copy link
Collaborator

StefH commented Sep 23, 2019

Closing

@StefH StefH closed this as completed Sep 23, 2019
@StefH StefH added the bug label Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants