Aspnetcore: Stream Request.Body is corrupted in Docker for Windows environment

Created on 19 Jul 2016  路  11Comments  路  Source: dotnet/aspnetcore

I have a following code snippet in my ASP.NET Core Controller :

``` c#
public IActionResult PostAction() {
string result;
using (var sr = new StreamReader(Request.Body)) {
result = sr.ReadToEnd();
}
...
}

In works just fine on stand-alone Kestrel on Win, Linux and docker under Linux (Ubuntu 14.04)

But the stream is somehow corrupted in Docker for Windows environment.
Sometimes there are redundant bytes/chars in the end of the stream
Sometime the stream is corrupted, somewhere about position 4096
I have not idea what it means, that is just my observation :)

There is a repo with simple sample demonstrating the problem
https://github.com/kaatula/aspnetcore-docker/releases/tag/0.1
You also pull my docker image and try it:

``` powershell
docker run -p 5001:5001 -t kaatula/aspnetcore-docker:v0.1

My docker image is based on latest preview2-sdk

In my sample i POST some data to my controller action (about 20kb) and just send in back;
on the client side I verify that received data is not corrupted.
image

I also write to console the received string

Most helpful comment

Hi, I work at Docker. We suspect that this is a bug in Docker for Windows and are investigating. I'll keep you posted on this issue.

Thanks for reporting!

All 11 comments

You shouldn't be disposing the response body in your controller action (I'm not sure if that's the problem but it's incorrect anyways)

@davidfowl thank you for pointing that out, I misread that this overload closed underlying stream too
Unfortunately, it's still makes no difference...

/cc @halter73 @cesarbs @mikeharder

I have just found that things are a way worse than I thought.

Regular MVC Action parameter convertion fails too, in exactly the same way.

``` c#
public IActionResult PostActionWithParameter(string data) {
Console.WriteLine(data);
return Content(data);
}

``` javascript
function postWithParam() {
    var numberString = "",
        numbers = [],
        i;
    for (i = 0; i < 20000; i++) {
        numbers.push(i % 10);
    }


    $.post("/Home/PostActionWithParameter/", {
        data: numbers.join("")
    }).then(function success(result) {
        var i;
        var checkResult = "OK";
        for (i = 0; i < result.length; i++) {
            var digit = i % 10;
            if (result[i] !== digit.toString()) {
                checkResult = "Failed!!!!";
            }
        }

        alert(checkResult + "\n" + result);
    })
}

When data is more than 4K - data string is not correct.

Again, it happens in Docker for Windows only, base image microsoft/dotnet:1.0.0-preview2-sdk (I have not tried other base images yet, only official one)

Updated repo:
https://github.com/kaatula/aspnetcore-docker/releases/tag/0.3

Updated docker image:

docker run -p 5001:5001 -t kaatula/aspnetcore-docker:v0.2

@kaatula: Thanks for reporting this issue. We are able to reproduce and will investigate the root cause.

+1

We are continuing to investigate the issue with Docker for Windows Beta. In our testing, this issue does not reproduce with Docker Toolbox, so you could use Docker Toolbox as a workaround for now.

Hi, I work at Docker. We suspect that this is a bug in Docker for Windows and are investigating. I'll keep you posted on this issue.

Thanks for reporting!

Also, using docker hostname (instead of localhost) will work as a temporary workaround - that hostname will be deprecated very soon though.

Relatedly, we've found the bug and a fix should be in the next release of Docker for Windows this out this week.

This has been fixed in the latest beta and stable releases: https://blog.docker.com/2016/07/docker-for-mac-and-windows-production-ready/

Thanks again for reporting!

Thank you, fix works just fine for me

Was this page helpful?
0 / 5 - 0 ratings