DataSnap server raises "The current session does not have permission to perform the requested action" when registering a callback

StackOverflow https://stackoverflow.com/questions/20546226

  •  01-09-2022
  •  | 
  •  

Question

I'm getting this error when I try to register a Callback after a connection/session loss.

I still didn't figure out exactly when it happens, if it is after after connection loss, after the server kills the session or something like it, I tried to force it in several ways but was not able to isolate exactly when it happens.

Debugging the Datasnap code, I noticed that it is raised because of a security token.

My "guess" is that this happens this way:

  • Client loses connection
  • Server didn't noticed the disconnection, previous session still active
  • Client reconnects, tries to register the new callback
  • Another session is created on the server
  • Callback is registered with the same security token as the previous session
  • Server blocks it, as this security token is already used on another session

Anyway, I get this after the client gets a connection error and I try to register the Callback again.

My client code looks like this:

CallbackChannelManager.CloseClientChannel; // Do I need to call this?
CallbackChannelManager.RegisterCallback(TDSTunnelSession.GenerateSessionId, TMyCallback.Create);

The Datasnap documentation about callbacks is so poor that I'm not even start with that, but, my questions are:

  • Do I really need to manually re-register all callbacks after a connection/session loss?
  • If so, what's the proper way to do it?
  • Do I have to instantiate a new CallbackChannelManager for each connection so I can get a new security token? (This is based on my guess about why this happens)

Thanks.

Was it helpful?

Solution

The problem was caused because I was using the same CallbackChannelManager.ManagerId to re-register the callback.

I started generating a new ManagerId before re-registering the callback and the error stopped, so now my code looks like:

CallbackChannelManager.CloseClientChannel;
CallbackChannelManager.ManagerId := TDSTunnelSession.GenerateSessionId;
CallbackChannelManager.RegisterCallback(TDSTunnelSession.GenerateSessionId, TMyCallback.Create);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top