This is more a question regarding understanding how and when Nancy might cancel an async request handler via the provided cancellationToken instance.
Basically what I am wondering about is in what conditions is the token's .IsCancellationRequested set to true - is this documented or explained somewhere?
How does Nancy handle async handlers that 'never' return / in 'time'? And regarding 'in time': is there a timeout / limit after which handlers do get cancelled?
I know this is an old question but I was in your same situation and I think I found an answer at least if you are using Owin to host your app (using Nancy.Owin
).
The CancellationToken
comes directly from Owin via the IOwinRequest.CallCancelled
property (Nancy source code and used here). This token can be set by Owin if the request is cancelled (for example by forcibly closing the HTTP connection).
Every CancellationToken comes from somewhere, and that somewhere is its CancellationTokenSource.
When you call CancellationTokenSource.Cancel, every token created from it is flagged.
Fun fact: CancellationToken is a struct, which means every time you pass it to a function or assign it to a variable it makes a new copy. Since the source can't keep track of all of those copies, we can't have a CancellationToken.IWasCancelled event. Instead, when you call IsCancellationRequested, the token has to asks its source.
ref: https://msdn.microsoft.com/en-us/library/system.threading.cancellationtokensource(v=vs.110).aspx
So going back to Nancy, search their source code for CancellationTokenSource and you'll find your answer. Here's the only one I saw.
https://github.com/NancyFx/Nancy/blob/8a29b0495bfac4806536327c4d78de1ee59bd513/src/Nancy/NancyEngine.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With