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

PubSub: Unobserved InvalidOperationException in AsyncSingleRecvQueue #2763

Closed
lkts opened this issue Dec 11, 2018 · 1 comment · Fixed by #2785
Closed

PubSub: Unobserved InvalidOperationException in AsyncSingleRecvQueue #2763

lkts opened this issue Dec 11, 2018 · 1 comment · Fixed by #2785
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lkts
Copy link
Contributor

lkts commented Dec 11, 2018

Hi,

My application that uses PubSub has logging handler for TaskScheduler.UnobservedTaskException.
Recently i have found out that such exceptions are constantly produced with stacktrace leading to PubSub (can be up to hundred in 10 minutes).
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. (An attempt was made to transition a task to a final state when it had already completed.) 
---> System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
   at Google.Cloud.PubSub.V1.SubscriberClientImpl.AsyncSingleRecvQueue`1.Enqueue(T item)
   at Google.Cloud.PubSub.V1.SubscriberClientImpl.SingleChannel.<>c__DisplayClass39_0.<Add>b__0(Task _)
   at System.Threading.ExecutionContext.RunInternal(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)
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
   at Google.Cloud.PubSub.V1.SubscriberClientImpl.AsyncSingleRecvQueue`1.Enqueue(T item)
   at Google.Cloud.PubSub.V1.SubscriberClientImpl.SingleChannel.<>c__DisplayClass39_0.<Add>b__0(Task _)
   at System.Threading.ExecutionContext.RunInternal(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)<---

Looks like race in code below since it is not in lock.

I believe there are no functional bugs because of that but ideally library should not produce such things :)

Thanks.

@jskeet
Copy link
Collaborator

jskeet commented Dec 11, 2018

Thanks for reporting this! (I'm currently looking at unobserved task exceptions in Spanner, but I don't expect it's caused by the same issue.)

@JustinBeckwith JustinBeckwith added triage me I really want to be triaged. 🚨 This issue needs some love. labels Dec 12, 2018
@chrisdunelm chrisdunelm added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants