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

Linux, exception in EasyRequest.Cleanup() when HttpCompletionOption.ResponseHeadersRead used #20258

Closed
pelhu opened this issue Feb 17, 2017 · 4 comments
Labels
area-System.Net.Http bug os-linux Linux OS (any supported distro)
Milestone

Comments

@pelhu
Copy link

pelhu commented Feb 17, 2017

Hi,
When i run on Ubuntu 14.04.5 LTS

using (var hc = new HttpClient())
{
	var req = new HttpRequestMessage(HttpMethod.Post, "http://cti.crypttech.com/home/test");
	var content = new MultipartFormDataContent();

	content.Add(new StringContent("dummyKey1"), $"\"dummyValue1\"");
	content.Add(new StringContent("dummyKey2"), $"\"dummyValue2\"");

	req.Content = content;

	var res = hc.SendAsync(req, HttpCompletionOption.ResponseHeadersRead).Result;
	var resultStream = res.Content.ReadAsStreamAsync().Result;

	using (var fs = File.OpenWrite(@"result.dat"))
	{
		resultStream.CopyTo(fs);
	}
}

I have error

Source: System.Private.CoreLib
Type: System.IO.IOException
Message: The read operation failed, see inner exception.
Stack trace:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Net.Http.CurlHandler.CurlResponseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Http.DelegatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
   at TestClient.Program.Main(String[] args) in C:\TestClient\Program.cs:line 68

Source: System.Private.CoreLib
Type: System.ObjectDisposedException
Message: Cannot access a closed Stream.
Stack trace:    at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.get_Length()
   at System.Net.Http.MultipartContent.ContentReadStream.set_Position(Int64 value)
   at System.Net.Http.CurlHandler.EasyRequest.Cleanup()
   at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)

Some times i have other error

Source: System.Private.CoreLib
Type: System.IO.IOException
Message: The read operation failed, see inner exception.
Stack trace:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Net.Http.CurlHandler.CurlResponseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Http.DelegatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
   at TestClient.Program.Main(String[] args) in C:\Users\khamzatsalikhov\Source\Workspaces\MicroCollection\SmartRest\TestClient\Program.cs:line 68

Source: System.Private.CoreLib
Type: System.ObjectDisposedException
Message: Cannot access a closed Stream.
Stack trace:    at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.MemoryStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.MultipartContent.ContentReadStream.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Net.Http.CurlHandler.MultiAgent.TransferDataFromRequestStream(IntPtr buffer, Int32 length, EasyRequest easy)
   at System.Net.Http.CurlHandler.MultiAgent.CurlSendCallback(IntPtr buffer, UInt64 size, UInt64 nitems, IntPtr context)

No problem occurs if i do not use "MultipartFormDataContent" or put "HttpCompletionOption.ResponseContentRead". But for me it's not possible because I download very large files by post with "MultipartFormDataContent".

Best regards

@stephentoub
Copy link
Member

@pelhu, I suspect this is the same as https://github.com/dotnet/corefx/issues/9006. I don't have access to the link in your repro (I get a 404), but do you know if the server starts sending back a response before it fully receives the request? I'm guessing it does.

@Priya91
Copy link
Contributor

Priya91 commented Apr 12, 2017

@stephentoub The callstack seems very similar to dotnet/corefx#17010, could that also be related to #17467

@stephentoub
Copy link
Member

@stephentoub The callstack seems very similar to dotnet/corefx#17010, could that also be related to #17467

It's possible. If you're able to repro it with that example, you could try changing the server to fully consume the request before outputting the response and see if that causes the failure to go away. If it does, it's almost certainly the same issue.

@Priya91
Copy link
Contributor

Priya91 commented Apr 13, 2017

Thanks @stephentoub will try it out.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http bug os-linux Linux OS (any supported distro)
Projects
None yet
Development

No branches or pull requests

4 participants