Skip to content

CurlHandler exception on resource constraint environment #20578

@NicolasDorier

Description

@NicolasDorier

The following exception happens on .NET Core runtime 1.1.1 on Ubuntu 14.04, when resources are constrained.

Uncatched exception in BroadcasterJob: System.IO.IOException: The read operation failed, see inner exception. ---> System.ObjectDisposedException: Cannot access a closed Stream.
         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.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)
         --- End of inner exception stack trace ---
         at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
         at System.IO.Stream.<CopyToAsyncInternal>d__27.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)

I am using CopyToAsync on a stream from a WebResponse.GetResponseStream() to a MemoryStream. I imagine something is garbage collected at the wrong time.

The MemoryStream at the top of the exception stack does not seems to be the same as the one passed to CopyToAsync. I experienced the same problem with simple Read(), same stacktrace, on the WebResponse stream.

Another example:

System.ObjectDisposedException: Cannot access a closed Stream.
         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.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)
         --- End of 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)

I am investigating it,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions