The CancellationTokenSource associated with this CancellationToken has been disposed.

1,039 views
Skip to first unread message

Phillip Haydon

unread,
Dec 17, 2015, 1:25:09 PM12/17/15
to RavenDB - 2nd generation document database
I'm getting a token disposed exception and I've narrowed it down to a single query.

var info = await DocumentSession.Query<Member_Info_Index.UserInfoResult, Member_Info_Index>()
                                                 
.SingleAsync(x => x.UserId == ctx.CurrentUser.UserName, token)
                                                 
.ConfigureAwait(false);


Any other query executed works fine, except this one.

It worked when using

Client: 3.0.3821-Unstable
Server: 3.0.8000

I updated the server to 3.0.30000, and it worked fine. I then updated the client to 3.0.30000, and it broke.

If I downgrade back to 3.0.3821-Unstable, everything works fine again.

There's no errors on the server. 

I donno what other information to give you. Let me know and I can source it. 

I tried rebuilding the index and that didn't help :(


Nancy.RequestExecutionException: Oh noes! ---> System.ObjectDisposedException: The CancellationTokenSource associated with this CancellationToken has been disposed.
at System.Threading.CancellationToken.ThrowObjectDisposedException()
at System.Threading.Tasks.Task.AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
at System.Threading.Tasks.Task.ContinueWithCore(Task continuationTask, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions options)
at System.Threading.Tasks.Task`1.ContinueWith[TNewResult](Func`2 continuationFunction, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, StackCrawlMark& stackMark)
at System.Threading.Tasks.Task`1.ContinueWith[TNewResult](Func`2 continuationFunction, CancellationToken cancellationToken)
at Raven.Abstractions.Extensions.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken token) in c:\Builds\RavenDB-Stable-3.0\Raven.Abstractions\Extensions\TaskExtensions.cs:line 65
at Raven.Client.Document.AbstractDocumentQuery`2.d__48.MoveNext() in c:\Builds\RavenDB-Stable-3.0\Raven.Client.Lightweight\Document\AbstractDocumentQuery.cs:line 2297 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.LinqExtensions.d__43`1.MoveNext() in c:\Builds\RavenDB-Stable-3.0\Raven.Client.Lightweight\PublicExtensions\LinqExtensions.cs:line 0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at HyRes.Website.Modules.RavenDbModule.<b__41_0>d.MoveNext() in E:\github\HyRes\src\HyRes.Website\Modules\RavenDbModule.cs:line 202 --- End of inner exception stack trace --- at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.LinqExtensions.d__43`1.MoveNext() in c:\Builds\RavenDB-Stable-3.0\Raven.Client.Lightweight\PublicExtensions\LinqExtensions.cs:line 0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at HyRes.Website.Modules.RavenDbModule.<b__41_0>d.MoveNext() in E:\github\HyRes\src\HyRes.Website\Modules\RavenDbModule.cs:line 202 --- End of inner exception stack trace --- at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at HyRes.Website.Modules.RavenDbModule.<b__41_0>d.MoveNext() in E:\github\HyRes\src\HyRes.Website\Modules\RavenDbModule.cs:line 202 --- End of inner exception stack trace --- at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)
--- End of inner exception stack trace ---
at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)

Phillip Haydon

unread,
Dec 17, 2015, 1:26:44 PM12/17/15
to RavenDB - 2nd generation document database
Oh, also if I configure the token to be None.

                        var info = await DocumentSession.Query<Member_Info_Index.UserInfoResult, Member_Info_Index>()

                                                       
.SingleAsync(x => x.UserId == ctx.CurrentUser.UserName, CancellationToken.None)
                                                       
.ConfigureAwait(false);


It works perfectly fine and grabs the data.

All other queries before / after also execute fine using the existing token passed in by Nancy.

Oren Eini (Ayende Rahien)

unread,
Dec 17, 2015, 2:49:12 PM12/17/15
to ravendb
Just to verify, the token you are passing there has not been disposed, right?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Phillip Haydon

unread,
Dec 17, 2015, 2:58:10 PM12/17/15
to RavenDB - 2nd generation document database
Correct, it's not been disposed.

So there's 2 lines where this happens.


                       
var member = await DocumentSession.LoadAsync<Member>(ctx.CurrentUser.UserName, token)
                                                         
.ConfigureAwait(false);



                       
var info = await DocumentSession.Query<Member_Info_Index.UserInfoResult, Member_Info_Index>()
                                                       
.SingleAsync(x => x.UserId == ctx.CurrentUser.UserName, CancellationToken.None)
                                                       
.ConfigureAwait(false);


If I run this with the 2nd query set to use `token`, it executes and gets member, if I debug token is still valid and I have member data.

When it executes the 2nd query, it throws the exception.

When set to None, it executes the first query, executes the 2nd query, falls through the next lot of code which does additional queries to RavenDB using the same token. No issues at all.

Very strange behavior. 

Oren Eini (Ayende Rahien)

unread,
Dec 17, 2015, 3:19:47 PM12/17/15
to ravendb
I can't get it to fail, see the attached test.

AsyncWithToken.cs

Phillip Haydon

unread,
Dec 17, 2015, 10:43:41 PM12/17/15
to RavenDB - 2nd generation document database
I tried creating a new token to run across the two queries.

Original code:

Before 1st query: Token is not disposed
Before 2nd query: Token is disposed

With new token:

Before 1st query: Token is not disposed
Before 2nd query: Token is not disposed
After 2nd query: Token is not disposed

When new token on 1st query, and old token on 2nd query.

Before 1st query: Both tokens are not disposed
Before 2nd query: New token is not disposed, old token is disposed...

-------------


This makes absolutely 0 sense to me at all. I can't tell if its a nancy issue or ravendb issue. :(

Oren Eini (Ayende Rahien)

unread,
Dec 18, 2015, 4:27:21 AM12/18/15
to ravendb
Can you try to create an isolated test case? 
Because I looked at the code, and the unit test is working, and I don't know how this can be.

Phillip Haydon

unread,
Dec 21, 2015, 8:42:38 AM12/21/15
to RavenDB - 2nd generation document database
https://github.com/NancyFx/Nancy/issues/2141#issuecomment-166288512

It turned out to be an issue in Nancy.

Case closed. 

Sorry for not replying sooner, was busy.
Reply all
Reply to author
Forward
0 new messages