Successfully clearing ports in Salome (Code ASTER)
How Salome tracks ports
When Salome is starting up, it checks for free ports on your system using a few built-in Python scripts. Then when you close Salome those ports should be freed up again for the next one. This has a number of uses, but one reason is to stop multiple instances of Salome trying to use the same port at once.
Those Python scripts keep track of the port numbers that are currently in use by storing the numbers in some configuration files (*.cfg) that are saved on your system. When Salome exits, those configuration files should be updated to recognize that the current port is being freed up again.
A possible problem with port tracking
Sometimes, however, those configuration files do not get updated. For example, if you are running Salome using a script in batch mode you can include a command to kill Salome properly, giving the correct port number. I have found in the past that this method has not been very reliable and so the configuration file keeps being updated with port numbers that are in use, but those numbers are never removed from the “in use” list even if they have actually been freed up on the system.
If you do a lot of scripting in salome you will find that when writing/testing your scripts, if salome crashes a lot then often the ports being used don’t get released and so stay as “being used” in the port log file.
The result is that after a while a maximum number of ports is reached and Salome thinks that there are no ports free, so it will not start successfully, giving the following error message:
RuntimeError:
Can’t find a free port to launch omniNames
Try to kill the running servers and then launch SALOME again.
Perhaps you will check for salome instances running using. There may or may not be lots of Salome processes running on your system. In this post I am going to assume that Salome has closed properly. You can check if salome is running:
ps -x | grep salome
Salome provides some Python scripts that should kill any running instances in a well-behaved way. For example, killSalome.py kills all of the instances running on your system, so you should use it with care:
~/bin/SALOME-8.2.0-UB16.04/BINARIES-UB16.04/KERNEL/bin/salome/killSalome.py
But if you already know the port number of a specific instance, killSalomeWithPort.py can be invoked to kill just that one, without affecting other instances that are currently running:
~/bin/SALOME-8.2.0-UB16.04/BINARIES-UB16.04/KERNEL/bin/salome/killSalomeWithPort.py 21116
ps x | grep salome | awk ‘{print $1}’ | xargs -n1 kill
Clearing the port config files
$ find . -name *.cfg./bin/SALOME-8.2.0-UB16.04/BINARIES-UB16.04/KERNEL/share/salome/resources/kernel/channel.cfg./bin/SALOME-8.2.0-UB16.04/BINARIES-UB16.04/SMESH/share/salome/plugins/smesh/padder.cfg… plus a load of non-salome-related stuff…
~/bin/SALOME-8.2.0-UB16.04/BINARIES-UB16.04/SALOME/USERS$ ls -a. ..
- .omniORB_PortManager.cfg
- Stores a list of the busy ports
- .omniORB_PortManager.lock
- Locks the .omniORB_PortManager.cfg from being edited? I’m not sure exactly what it locks.
- .omniORB_<username>_<hostname>_<port>.cfg
- Should be deleted each time but if Salome is not doing this you will have many of these files with different port numbers.
- .omniORB_<username>_last.cfg
- I guess this probably stores the last port that was used, although I deleted it already before confirming this hunch.
On one of my systems (a HPC cluster) Salome was not storing the .omniORB_PortManager.cfg file in /tmp/ . Instead it was located in /home/<username>/bin/salome/appli_V7_6_0/USERS
You can check which path is being used by looking in /home/<username>/bin/salome/appli_V7_6_0/bin/salome/PortManager.py In there is a variable named “omniorbUserPath”, which is obtained from an environment variable that I could not see. Nonetheless, I modified PortManager.py to print this variable to screen, which told me that it was looking for /home/<username>/bin/salome/appli_V7_6_0/USERS/.omniORB_PortManager.cfg . Believe me, this was very frustrating to identify as I really thought I had deleted all necessary files, only for salome to continue not finding a free port!
You can delete all of these files, and now when you run Salome it will start fresh, creating new files as it needs. Problem fixed! But…
Stop it happening again
<salome_distro>/salome --ns-port-log="somefolder/salomePort.log" -t -b script.py port_file = open('somefolder/salomePort.log' , 'r') killPort = int(port_file.readline()) <salome_distro>/bin/salome/killSalomeWithPort.py %s' % killPort
if not salome.sg.hasDesktop(): from killSalomeWithPort import killMyPort killMyPort(os.getenv('NSPORT'))
Footnotes
- I am using the Salome version 8.2.0 for Ubuntu 16.04 x64 precompiled binaries. Different versions have different file structures and so your binary folder path might be different. If you search on the command line for e.g. runSalome.py, you should be able to identify where your salome binaries and Python scripts are located.
- A lot of this info was gleaned from the Salome user forum, particularly from this 2015 post: http://www.salome-platform.org/forum/forum_10/519093933
- In Linux, hidden files have a full stop (US: “period”) in front of their filename. To see them when listing a directory use “ls -a”.
- For more information about why Salome needs to use ports, check out the Salome FAQ.