question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: Cannot access a disposed object. Object name: 'SslStream'

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I’m getting two new issues using the latest prerelease version and they are somewhat related so I’m going to put them both on here. They both seem to occur right after the other

First: Cannot access a disposed object.
Object name: 'SslStream'.

   at System.Net.Security.SslStream.<ThrowIfExceptional>g__ThrowExceptional|138_0(ExceptionDispatchInfo e)
   at System.Net.Security.SslStream.WriteAsync(ReadOnlyMemory`1 buffer, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.WriteToStreamAsync(ReadOnlyMemory`1 source, Boolean async)
   at System.Net.Http.HttpConnection.FlushAsync(Boolean async)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
Exception Type:
System.TimeoutException

Exception Message:
HTTP response timed out.

Exception StackTrace:
   at Alpaca.Markets.ThrottleParameters.CustomHttpHandler.sendAsyncWithTimeout(HttpRequestMessage request, CancellationToken cancellationToken)
   at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Func`5 onRetryAsync, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider, Boolean continueOnCapturedContext)
   at Polly.AsyncPolicy`1.ExecuteAsync(Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
   at Polly.Wrap.AsyncPolicyWrapEngine.<>c__DisplayClass2_0`1.<<ImplementationAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Func`5 onRetryAsync, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider, Boolean continueOnCapturedContext)
   at Polly.AsyncPolicy.ExecuteAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
   at Polly.Wrap.AsyncPolicyWrapEngine.ImplementationAsync[TResult](Func`3 func, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy`1 innerPolicy)
   at Polly.AsyncPolicy`1.ExecuteAsync(Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
   at Alpaca.Markets.ThrottleParameters.CustomHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpMessageInvoker httpClient, HttpRequestMessage request, CancellationToken cancellationToken)
   at Alpaca.Markets.HttpClientExtensions.callAndDeserializeAsync[TApi,TJson](HttpMessageInvoker httpClient, HttpMethod method, Uri endpointUri, CancellationToken cancellationToken)
   at OoplesFinanceAdminClient.AlpacaApi.GetTopLevelInfo() in E:\OoplesFinanceAdminClient\OoplesFinanceAdminClient\AlpacaApi.cs:line 2063

Exception Target Site:
MoveNext

Exception Source:
Alpaca.Markets

A task was canceled.

   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Alpaca.Markets.ThrottleParameters.CustomHttpHandler.sendAsyncWithTimeout(HttpRequestMessage request, CancellationToken cancellationToken)

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- SDK Version: 6.03 rc2
- OS (version, bitness): Windows 10 
- .NET SDK (version): .net 6
- target process .NET version/bitness: 64 bit

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ooplescommented, May 20, 2022

@OlegRa Also as a side note, I looked through the user wiki and tutorials and didn’t see an example for newer users to utilize the throttle parameters so just thought it would be useful to add an example

0reactions
OlegRacommented, May 31, 2022

@OlegRa I’m able to replicate this by disabling the ethernet adapter and then enabling it again. Socket stays closed and doesn’t attempt to reconnect. However when running the same code without messing with the ethernet adapter, I can see that it does attempt to reconnect on its own.

@ooples How does socket reconnection logic (most probably your mean one of the streaming clients) relate to the HTTP timeout? If you have a problem related to streaming client’s reconnection in the latest SDK release, please, report it as a separate issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot access a disposed object. Object name: 'SslStream'.
I have an issue with SendAsync in .NET Core 2.2. When doing a lot of requests, I encounter the exception on some of...
Read more >
Cannot access a disposed object. Object name: 'SslStream'
Object name : 'SslStream' We have an service bus triggered Azure function which makes a call to an http triggered Azure function and...
Read more >
Cannot access a disposed object: SslStream (CopyToAsync)
Hello,. we download blobs from Azure Storage through our intern tool written in C# WPF and we have got problems with it recently....
Read more >
Error Message Cannot access a disposed object Obje...
Cannot access a disposed object. Object name: 'SslStream'. You can clear your Desktop cache and then try refresh in Desktop again . In...
Read more >
[XMPP] Cannot Access a disposed Object. Object Name: ' ...
I am getting Error Message: [XMPP] Cannot Access a disposed Object. Object Name: 'SslStream'. Not able to Sync my Emails. Please advise how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found