What are Ghosts Sessions?
When you lose your network connection or your FileMaker quits, sometimes your session doesn’t drop off on the FileMaker server. This becomes a problem when that session hogs up one of your license spots. This doesn’t seem to happen often, but when I talked prentices to colleagues at the annual FileMaker Developer Conference, I learned it happens more often than we think.
The Process to Eliminate Ghost Sessions
So, once we identify we have a problem, we can start cooking up a solution. This particular server happens to be Windows Server. First I thought about VB scripting or Power Shell scripting. To be honest I’ve written one small Power Shell script, but this seemed a little above my head. So, I thought, well, here’s a tool I know how to use: FileMaker. I wonder if it can do the job. It can, indeed.
The process is basically the following:
- Issue a command in Command Line to get a list of connected clients;
- Create records in a table;
- Compare them to see which ones are the same (same IP address or user);
- Issue a disconnect for everyone except for the newest connection.
So how do we do this from FileMaker? With the use of a plug-in, of course. In this case I grabbed the Base Elements plug-in, because it was already installed on the server.
The Base Elements plug-in can issue Command Line commands. I use it to get the list of connected clients:
BE_ExecuteSystemCommand ( “fmsadmin list clients -s -u <username>r -p <password>” )
The result comes back in fixed-width text format — which gave me a little headache, but I learned a lot from it. Fixed-width means that every word has a certain amount of space and the data is separated by an indeterminable number of spaces. To get that data into arrays, you have to calculate the position of the column headers.
Let (
[
text = GetValue ( $BE_output ; 1 ) ;
$pID = Position ( text ; "Client ID" ; 1 ; 1 );
$pUname = Position ( text ; "User Name" ; 1 ; 1 ) ;
$pCname = Position ( text ; "Computer Name" ; 1 ; 1 ) ;
$pCon = Position ( text ; "Connect Time" ; 1 ; 1 ) ;
$pDur = Position ( text ; "Duration" ; 1 ; 1 )
];
$pID & ¶ &
$pUname & ¶ &
$pCname & ¶ &
$pCon & ¶ &
$pDur
)
I then go through the result and create records from it. Now I have records to compare the timestamp on the similar records.
The way I do that is by setting up another table occurrence (user = user in my case) and then checking whether the record is a duplicate via this calculations:
TimeStamp ≠ Max ( UT__UtilityTable_User::TimeStamp )
Here is my table:
Disconnecting the Ghost Sessions
The last thing is to find the records that are marked duplicate and then loop through to issue a disconnect command for them:
# Loop through the dups and disconnect
Go to Record/Request/Page [ First ]
Set Variable [ $rep; Value:1 ]
Set Variable [ $maxReps; Value:Get (FoundCount) ]
Loop
# Disconnect the client(s)
Set Variable [ $ID; Value:UT__UtilityTable::ID ]
Set Variable [ $command; Value:"fmsadmin disconnect client " & $ID & " -y " & " -u " & $username & " -p " & $password ]
Set Variable [ $BE_output; Value:BE_ExecuteSystemCommand ( $command ) ]
Set Variable [ $error; Value:BE_GetLastError ]
If [ $error > 0 ]
Send Mail [ Send yourself an email via SMTP so you know when there was a user disconnected.][ No dialog ]
End If
Exit Loop If [ $rep = $maxReps ]
Go to Record/Request/Page [ Next ]
End Loop
As you can see I’m using username and password variables above. Those are set in my script with the FileMaker Admin console access values I need to issue the command line commands.
Following these steps should help you eliminate ghost sessions in FileMaker and avoid overusing unnecessary license spots. Good luck! If you have any questions, let me know in a comment below or contact my team directly.
This is a fantastically useful article. The problem has definitely happened to me. Thanks very much for this tip.
Hi Nick,
Thank you so much! I’m glad you found it useful.
Agnes
Thanks, Agnes! This one is going in the tool chest.
Glad you have found Agnes’ post useful!
Agnes
This doesn’t work… I have added cmd.exe /c to the start as per the BaseElements help but it just creates a ghost session of its own that refuses to disconnect and locks up the calling FileMaker file
John,
I’m sorry that FileMaker Server did not respond to the command. Just as FileMaker Server might not respond to a command you initiate from the Admin Console, so too might be the case with the command line. In that case I recommend using the Admin Console (or command line) to close all the hosted files, stop FileMaker Server, restart the server computer, and then restart FileMaker Server, if it is not set to do so automatically on startup.
Best of Luck,
Dawn
Pingback: FileMaker 16 cURL, Ghost Sessions, Motivation - FileMakerProGurus
Thank you, this works really well. However, fmsadmin does not appear to have an option for disconnecting without the user’s agreement. I am implementing a system which would request a user, who has logged in on more than one device, to log out on the other device. As such, the user will likely not be available to agree to the request on the more distant device. Is there any way to do this?
I notice that the disconnection does in fact occur without the user’s agreement, after a pause.
Hi, I thought this was our saving grace for one of our bigger client that constantly does ghost sessions. Unfortunately, it does the same thing as xjohn renfrew mentionned : it hangs, then keeps an infinite PSOS session on the server that is unclosable by server console or command line.
I tried the same method at 3 other client’s database, and it worked flawlessly. It’s not about being on a Windows server as I’ve made it work on one, neither it is excessive security that would prevent command lines from being executed as I can to a remote session and easily execute the exact same command line and obtain the connection client list.
Have you ever found a reason this would happen? I’m wondering if it’s related to what causes them to actually produce ghost sessions in the first place.
Hi Marc-Andre,
Our approach to monitoring and trying to kill ghost sessions has evolved since this article. We now try and use industry-standard monitoring tools like Zabbix (see our blog posts on monitoring) that can check for and them and can execute command line commands without having to try to do those from inside FM.
As to main reasons for ghost sessions: in our experience it is often the use of ESS and/or trouble on the network (a saturated network, bad cabling, spotty wifi, failing network equipment that generates lots of disconnects).
Hi Wim, and thank you for your answer!
That’s an interesting avenue, last question : sometimes, it we see stuck sessions on the server console and can close them from there (which would give the possibility for sure of doing it from an external software or command line). But other times, we have the same symptoms, but there is no session on the server that we can close.
Are you aware if Zabbix would make possible to kick out more ips than the ones we see in the Filemaker Console?
Thank you very much!
Not sure I fully understand where the “more IPs than we see in the Console” would come from?
But in general: no. Zabbix would have to use the available FMS tools to get a list of connected clients. Either through the Admin CLI or the Admin API. If you have connections that are not returned in those lists then Zabbix would not be aware of them.
Thanks, that’s what I thought! We’ll probably still look at something like Zabbix, because managing the visible connections is still worth it. I’ll continue looking for the invisible ones. Doesn’t happen often, but needs server restart when it does, as the users get ” (?) is modifying the record” error. I don’t have much hope, as Claris themselves don’t know any cause.
Thanks for this post.
Made me help with a FileMaker server 18 customer.