Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-1429

NotSupportedException thrown when SSL enabled under high concurrency

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.4, 2.4.5
    • Fix Version/s: 2.4.6
    • Component/s: library
    • Labels:
      None

      Description

      This test intermittently fails; looking at the logs, it looks like a currency issue where more than one thread invokes the synchronous Send method.

       

      2017-05-16 18:14:24,963 [22] DEBUG Couchbase.IO.Services.PooledIOService - System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: The BeginRead method cannot be called when another read operation is pending.
      at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
      at System.Net.Security._SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)
      at System.IO.Stream.<>c.<BeginEndReadAsync>b__43_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
      at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
      at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 count)
      at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
      at Couchbase.IO.SslConnection.<SendAsync>d__7.MoveNext() in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\IO\SslConnection.cs:line 201
      — End of inner exception stack trace —
      at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
      at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
      at System.Threading.Tasks.Task.Wait(CancellationToken cancellationToken)
      at Couchbase.IO.SslConnection.Send(Byte[] buffer) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\IO\SslConnection.cs:line 175
      at Couchbase.IO.Services.PooledIOService.Execute[T](IOperation`1 operation) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\IO\Services\PooledIOService.cs:line 169
      ---> (Inner Exception #0) System.NotSupportedException: The BeginRead method cannot be called when another read operation is pending.
      at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
      at System.Net.Security._SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)
      at System.IO.Stream.<>c.<BeginEndReadAsync>b__43_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
      at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
      at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 count)
      at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
      at Couchbase.IO.SslConnection.<SendAsync>d__7.MoveNext() in C:\Users\jmorris\repos\couchbas

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

          Hide
          jmorris Jeff Morris added a comment - - edited

          The problem appears to be that when the SslConnection was rewritten some time back to call the async methods asynchronously, a subtle bug was introduced: 

          • The IOService calls connection.Send
          • connection.Send calls connection.SendAsync synchronously
          • connection.SendAsync returns the connection back to the queue (it was designed to be a fire and forget method since it can finish on any thread)
          • SendAsync returns back to Send
          • Send returns back to IOService
          • IOService returns the connection back the queue - it has now been enqueued twice (once in SendAsync and once here)
          • Next threads call IOService and dequeue connection with two references in the queue - each use SslStream simultaneously and the NotSupportedException is thrown. 
          Show
          jmorris Jeff Morris added a comment - - edited The problem appears to be that when the SslConnection was rewritten some time back to call the async methods asynchronously, a subtle bug was introduced:  The IOService calls connection.Send connection.Send calls connection.SendAsync synchronously connection.SendAsync returns the connection back to the queue (it was designed to be a fire and forget method since it can finish on any thread) SendAsync returns back to Send Send returns back to IOService IOService returns the connection back the queue - it has now been enqueued twice (once in SendAsync and once here) Next threads call IOService and dequeue connection with two references in the queue - each use SslStream simultaneously and the NotSupportedException is thrown. 

            People

            • Assignee:
              jmorris Jeff Morris
              Reporter:
              jmorris Jeff Morris
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes

                  PagerDuty

                  Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.