-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
500 on swagger json endpoint while logging response using middleware #288
Comments
Can you provide more details around the 500 response? For example, the exception that's driving it. You may need to enable the developer exception page to see this - i.e. UseDeveloperExceptionPage. |
Microsoft.AspNetCore.Server.Kestrel:Error: Connection id "0HL2Q5QC2C2OS": An unhandled exception was thrown by the application. System.ObjectDisposedException: Cannot access a closed Stream. |
@domaindrivendev The issue is with this line. Disposing the StreamWriter causes the underlying stream to get closed as well. Perhaps might be a good idea to just flush it instead. |
You can add the swagger middleware before adding the request/response logging middleware, so swagger requests won't get handled by the logging middleware. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
Maybe is it better not to close stream in RespondWithSwaggerJson() method? For example, Swashbuckle.AspNetCore conflicts with ZNetCS.AspNetCore.Compression because stream is closed (see this issue). There are some workarounds in this case: we can ignore compression for swagger.json or change order of middlewares. But in general, stream closing could be a problem. |
I hit the same issue, and ended with same analysis : it's not necessarly a good thing to close the stream (it doesn't add anything and can cause problems). Would you accept a PR to modify this? |
Having the same problem. Seems like other issues are being opened for the same underlying problem. +1 on leaving the stream open. The .Net core 2 WebApi docs are lacking but I don't think ur supposed to close the stream. |
@treziac - sorry about the slow response. This does seem like a critical issue that could be easily remedied. A PR would certainly be welcomed! |
@domaindrivendev #509 solves the issue, would be nice to see it merged ;) |
fix #288 : leave response stream open on swagger json endpoint
Yay! Just in time with this merge. Thanks all! |
When I tried logging the response with the method provided here, I am getting 500 on the swagger endpoint. While I am able to get the response on calling the URI. Same issue mentioned in the comment.
The text was updated successfully, but these errors were encountered: