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

TaskScheduler UnobservedTaskException on long run of WCF 4.7.0 on .NetCore 3.1 (Win) #4301

Closed
SergeAgeyev opened this issue Jun 22, 2020 · 2 comments · Fixed by #4743
Closed
Assignees
Labels
bug This is a product bug.
Milestone

Comments

@SergeAgeyev
Copy link

SergeAgeyev commented Jun 22, 2020

Describe the bug
I our application (it uses a lot of WCF services with NetTcpBinding and HttpBinding), we observe TaskScheduler UnobservedTaskException after ~20 hours of operation when using WCF 4.7.0 on NetCore 3.1 (on Windows). The app using WCF to connect to Onvif video cameras and other WCF services as well.
By couple of reasons, we have to terminate application on UnobservedTaskException as system may become unstable in that case, so this prevent app to function properly.
The same code under full .Net Framework works fine.

To Reproduce
Run WCF-intense code for 24+ hours, then in some cases you see UnobservedTaskException
Unfortunately, there is no more specific information at the moment.
Probably this may somehow be related to network communication issues as well.

Expected behavior
The system should operate in a stable way.

Additional context

2020-06-22 06:00:46,895 [2] ERROR TaskScheduler_UnobservedTaskException Unhandled Exception

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The given key 'System.ServiceModel.Channels.RequestReplyCorrelator+Key: {urn:uuid:0828ae28-df71-4611-aeb6-XXXXXXXX, System.ServiceModel.Dispatcher.DuplexChannelBinder+IDuplexRequest}' was not present in the dictionary.)

---> System.Collections.Generic.KeyNotFoundException: The given key 'System.ServiceModel.Channels.RequestReplyCorrelator+Key: {urn:uuid:0828ae28-df71-4611-aeb6-f6a0bbdbc929, System.ServiceModel.Dispatcher.DuplexChannelBinder+IDuplexRequest}' was not present in the dictionary.

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at System.ServiceModel.Channels.RequestReplyCorrelator.System.ServiceModel.Channels.IRequestReplyCorrelator.Find[T](Message reply, Boolean remove)

   at System.ServiceModel.Dispatcher.DuplexChannelBinder.HandleRequestAsReplyCore(Message message)

   at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequestAsReply(RequestContext request)

   at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)

   at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)

   at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)

   at System.Runtime.TaskHelpers.<>c__1`1.<ToApm>b__1_1(Task`1 antecedent, Object obj)

   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location where exception was thrown ---

   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

   --- End of inner exception stack trace ---

2020-06-22 06:00:46,897 [2] ERROR TaskScheduler_UnobservedTaskException Unhandled Exception

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The given key 'System.ServiceModel.Channels.RequestReplyCorrelator+Key: {urn:uuid:49a1f53f-24ea-4ad5-b319-YYYYYYYY, System.ServiceModel.Dispatcher.DuplexChannelBinder+IDuplexRequest}' was not present in the dictionary.)

---> System.Collections.Generic.KeyNotFoundException: The given key 'System.ServiceModel.Channels.RequestReplyCorrelator+Key: {urn:uuid:49a1f53f-24ea-4ad5-b319-b14401fe9630, System.ServiceModel.Dispatcher.DuplexChannelBinder+IDuplexRequest}' was not present in the dictionary.

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at System.ServiceModel.Channels.RequestReplyCorrelator.System.ServiceModel.Channels.IRequestReplyCorrelator.Find[T](Message reply, Boolean remove)

   at System.ServiceModel.Dispatcher.DuplexChannelBinder.HandleRequestAsReplyCore(Message message)

   at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequestAsReply(RequestContext request)

   at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)

   at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)

   at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)

   at System.Runtime.TaskHelpers.<>c__1`1.<ToApm>b__1_1(Task`1 antecedent, Object obj)

   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location where exception was thrown ---

   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

   --- End of inner exception stack trace ---
@SergeAgeyev SergeAgeyev changed the title TaskScheduler UnobservedTaskException on long run of WCF 4.7.0 on .NetCore 3.1 TaskScheduler UnobservedTaskException on long run of WCF 4.7.0 on .NetCore 3.1 (Win) Jun 22, 2020
@HongGit HongGit added the bug This is a product bug. label Jun 25, 2020
@HongGit HongGit added this to the 6.0 milestone Oct 26, 2020
@HongGit
Copy link
Contributor

HongGit commented Oct 13, 2021

@mconnew ?

@mconnew
Copy link
Member

mconnew commented Oct 14, 2021

This was caused by switching from Hashtable to Dictionary and there being a change in behavior with the item getter. Dictionary[key] throws if the key isn't in the dictionary, whereas Hashtable[key] returns null. The scenario that this will occur under is when a callback happens and the callback method doesn't complete before something happens to the channel to shut it down. This would normally be a fault or abort as a regular close will wait for the request to be completed before continuing with the close. A close can timeout though, which turns it into an abort. I'm going to revert back to using Hashtable as we are only taking advantage of the generic type on the key, and it has some other concurrency advantages of being able to do lock free reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a product bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants