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

MemoryPoolHttpResponseStreamWriterFactory throws ArgumentNullException #1771

Closed
bongia opened this issue Sep 28, 2016 · 3 comments
Closed

MemoryPoolHttpResponseStreamWriterFactory throws ArgumentNullException #1771

bongia opened this issue Sep 28, 2016 · 3 comments

Comments

@bongia
Copy link

bongia commented Sep 28, 2016

Hi,
I have an exception which is thrown by AspNet code which I am not able to reproduce sistematically:

> System.ArgumentNullException: Value cannot be null.
Parameter name: stream
   at Microsoft.AspNetCore.Mvc.Internal.MemoryPoolHttpResponseStreamWriterFactory.CreateWriter(Stream stream, Encoding encoding)
   at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.<WriteResponseBodyAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultFilterAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAllResultFiltersAsync>d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResourceFilterAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

This seems to happen when the client is a browser (it happened using Angular2). With Postman or HttpClient I was not able to reproduce the issue.
The same angular2 app, running with Charles (https://www.charlesproxy.com/) active, is not affected by this problem.

This is the request sent without Charles:

> POST@/api/token
    **Connection:keep-alive**
    Content-Length:58
    Content-Type:application/json
    Accept:*/*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8,it;q=0.6
    Host:172.28.64.124:45678
    Referer:http://localhost:2020/login;next=true
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
    Origin:http://localhost:2020
    DNT:1

This is the request sent with Charles:

> POST@/api/token
        Content-Length:58
    Content-Type:application/json
    Accept:*/*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8,it;q=0.6
    Host:172.28.64.124:45678
    Referer:http://localhost:2020/login;next=null
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
    Origin:http://localhost:2020
    DNT:1

As you can see the only significant difference is that when it throws exception, the client sends also the Connection:keep-alive header. It might be also a problem related to CORS since we are doing cross domain requests and we never reproduced the error with non-browser clients

I am using the following packages and the application is running self-hosted on windows 10 (64bit)

> {
    "dependencies": {
        "Microsoft.AspnetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspnetCore.Server.Kestrel": "1.0.0",
        "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
        "Microsoft.AspnetCore.StaticFiles": "1.0.0",
        "Microsoft.AspnetCore.Authentication.JwtBearer": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": " 1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Caching.Abstractions": "1.0.0",
        "Microsoft.Extensions.Caching.Memory": "1.0.0",
        "System.IdentityModel.Tokens.Jwt": "5.0.0",
    },
    "frameworks": {
        "netcoreapp1.0": { }
    },
    "publishOptions": {
        "include": [
            "Properties"
        ]
    },
    "buildOptions": {
        "preserveCompilationContext": true
    }
}

Do you have ideas about the cause of the issue?
Thanks in advance

@rynowak
Copy link
Member

rynowak commented Sep 28, 2016

Thanks for the thorough report.

Do you have any code that messes with HttpContext.Response.Body? That stream that's null in this case is the Response.Body stream. https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonOutputFormatter.cs#L133

@CesarBS @halter73 @Tratcher seen anything as spooky as this before? The connection-keepalive part might be interesting.

@Tratcher
Copy link
Member

Could be the Kestrel response body reset bug fixed in 1.0.1. aspnet/KestrelHttpServer#1028

@bongia
Copy link
Author

bongia commented Sep 29, 2016

Thank you @Tratcher the issue seems to be solved.
@rynowak no, the exception was thrown before hitting my code.

I will keep you updated if the problem occurs again. Thank you

@bongia bongia closed this as completed Sep 29, 2016
ryanbrandenburg pushed a commit that referenced this issue Nov 27, 2018
Move Cpp Client to main repo (#1703)
dougbu pushed a commit to dotnet-maestro-bot/AspNetCore that referenced this issue Sep 11, 2019
dougbu pushed a commit to dotnet-maestro-bot/AspNetCore that referenced this issue Sep 11, 2019
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants