My datasnap server is using a TDictionary to support incoming connections and assign its database connection. Seems that after client closes the connection itself is not released, even that code is being called:

My datasnap server is using a TDictionary to support incoming connections and assign its database connection. Seems that after client closes the connection itself is not released, even that code is being called:
        if FConnections.ContainsKey(TDSSessionManager.GetThreadSession.Id) then
        begin
            FConnections.Remove(KeyConexao);
            FConnections.TrimExcess;
        end;

The issue here is my server runs with a lot of unused connections. As a workaround I put a timmer to 'kill' that connections, but I can't actually terminate them correctly. At a end of a day we got a lot of that connections and sometimes the clients are simply unable to connect to the server.

At the getconnection() method I have this code:

        Result.theDatabase := database;
        Result.timeout := Time(); // using to calcule the time to live
        Result.key := TDSSessionManager.GetThreadSession.Id;
        FConnections.Add(TDSSessionManager.GetThreadSession.Id, Result);

Any better way to solve this?

Comments