Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
master_t
Partner - Creator II
Partner - Creator II

Token disposed error in Qlik .NET SDK

Hello everyone

I'm using the Qlik Sense .NET SDK to interact with a Qlik SaaS app and, while doing it, I sometimes get "CancellationTokenSource has been disposed" errors like this:

System.ObjectDisposedException: The CancellationTokenSource has been disposed.
   at System.Threading.CancellationTokenSource.ThrowObjectDisposedException()
   at System.Threading.CancellationTokenSource.get_Token()
   at Qlik.Sense.JsonRpc.RpcConnection.get_CancellationToken()
   at Qlik.Engine.Communication.QlikConnection.Qlik.Engine.Communication.IQlikConnection.get_CancellationToken()
   at Qlik.Engine.App.BackCount()

 

In this case I was invoking the IApp.BackCount() method, but this can happen even when calling other methods.

Does anyone know what this error means exactly? Is it a disconnection? Why is the CancellationTokenSource getting randomly disposed in the middle of execution, and how can I diagnose the cause of this?

Labels (2)
5 Replies
Øystein_Kolsrud
Employee
Employee

I'm not sure why you end up with that "CancellationTokenSource disposed" error but I would guess it's due to the connection to QCS being dropped for some reason. There is a tendency for that to happen when working with SaaS solutions, more so than on-prem solutions. Unfortunately the .NET SDK does not today provide a good way to handle this transparently and reestablish the connection under the hood.

What you could to is to observe the "ConnectionClosing" event in the session. Like this:

app.Session.ConnectionClosingEvent += SessionOnConnectionClosingEvent;

That could at least give you a fair idea if this is really what is happening. You might also activate logging for the SDK and see if you see any traces of what is happening there.

master_t
Partner - Creator II
Partner - Creator II
Author

Hello Øystein_Kolsrud, thanks for your support.

Indeed, I have noticed relatively frequent timeouts/disconnections when using the SDK with QS SaaS. In addition to this one, I also tend to sometime get this one when connecting to an app on QCS:

System.TimeoutException: Method "QTProduct" timed out
at Qlik.Engine.Communication.QlikConnection.AwaitResponseTask[T](T task, String methodName, CancellationToken cancellationToken)
at Qlik.Engine.Communication.QlikConnection.AwaitResponse(Task task, String methodName, CancellationToken cancellationToken)
at Qlik.Engine.Communication.QlikConnection.Ping()
at Qlik.Sense.JsonRpc.GenericLocation.DisposeOnError(IDisposable o, Action f)
at Qlik.Engine.QcsLocation.Hub(String appId, String sessionToken, Dictionary`2 wsParameters)
at Qlik.Engine.QcsLocation.App(String appId, SessionToken sessionToken, Boolean noData)

 

Can I ask if this is this something that is known to the dev team and is being worked on? And are there any steps we can adopt on our end to mitigate the issue?

Øystein_Kolsrud
Employee
Employee

Unfortunately I believe these problems are due to transient issues with the network connections to the severs hosted in the cloud, so not something that can easily be remedied. The only solution I can come up with is to implement retry mechanisms for whatever operations you are doing. You could of course play around with extending timeouts and such, but that is unlikely to really solve your problem.

Making the SDK more robust in this area has certainly been considered. It's not a trivial thing to do though and would require a couple of API changes that would break backwards compatibility so we have been hesitant to do that.

master_t
Partner - Creator II
Partner - Creator II
Author

As a developer I understand completely... as a Qlik Partner however, I also have to justify to my customers why our applications that interact with QS are unreliable, which in turn means telling them that Qlik Cloud is unreliable... as you can imagine, this is not a very good look.

Does Qlik provide any official statements and/or metrics on the reliability of APIs and the QCS itself?

master_t
Partner - Creator II
Partner - Creator II
Author

Here's another error that I sometimes get randomly, again a transient disconnection:

 

System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
   at Qlik.Engine.Communication.QlikConnection.AwaitResponseTask[T](T task, String methodName, CancellationToken cancellationToken)
   at Qlik.Engine.Communication.QlikConnection.AwaitResponse[T](Task`1 task, String methodName, CancellationToken cancellationToken)
   at Qlik.Engine.App.Evaluate(String expression)

 

It really makes working with the Qlik Cloud API almost impossible, especially since it can happen when invoking any method that makes a request towards the Qlik engine (in this case it was the Evaluate() method). 

A retry mechanism is fine if the error happens when you first connect, but it can become quite complicated if (like this case) it happens in the middle of a session. I assume, for example, that the app session gets destroyed when this happens and thus any selections or soft patches that were previously applied are lost... makes a lot of cases really difficult to handle.

It would be great to have an official response from Qlik on their policies for this kind of issues. I think I'll open a support case in this regard.