Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid PID file overriden by additional ContextBroker instance #3075

Closed
fgalan opened this issue Jan 16, 2018 · 1 comment
Closed

Avoid PID file overriden by additional ContextBroker instance #3075

fgalan opened this issue Jan 16, 2018 · 1 comment

Comments

@fgalan
Copy link
Member

fgalan commented Jan 16, 2018

Case 1

Let's start CB using a given PID file:

contextBroker -pidpath /tmp/pidfile1.pid -fg

PID file is correctly filled:

$ ps ax | grep context
 17907 pts/2    Sl+    0:00 contextBroker -pidpath /tmp/pidfile1.pid -fg
 17932 pts/1    S+     0:00 grep context

$ cat /tmp/pidfile1.pid ; echo
17907

Now, I try to start a second instance of CB, running again contextBroker -pidpath /tmp/pidfile1.pid -fg. Of course, it fails, as the port is already in use:

time=Tuesday 16 Jan 10:11:23 2018.743Z | lvl=FATAL | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=rest.cpp[1744]:restStart | msg=Fatal Error (error starting REST interface)

However, PID file has lost its content, while the first instance is still running:

$ ps ax | grep context
 17907 pts/2    Sl+    0:00 contextBroker -pidpath /tmp/pidfile1.pid -fg
 17975 pts/1    S+     0:00 grep context

$ cat /tmp/pidfile1.pid ; echo
cat: /tmp/pidfile1.pid: No existe el fichero o el directorio

Case 2

Let's start CB using a given PID file:

contextBroker -pidpath /tmp/pidfile1.pid -fg

PID file is correctly filled:

$ ps ax | grep context
 17990 pts/2    Sl+    0:00 contextBroker -pidpath /tmp/pidfile1.pid -fg
 18018 pts/1    S+     0:00 grep context

$ cat /tmp/pidfile1.pid ; echo
17990

Now I run a second instance in a free port with ontextBroker -pidpath /tmp/pidfile1.pid -fg -port 1027 so the second instance runs. The situation is now:

fermin@neodeb:~$ ps ax | grep context
 17990 pts/2    Sl+    0:00 contextBroker -pidpath /tmp/pidfile1.pid -fg
 18026 pts/3    Sl+    0:00 contextBroker -pidpath /tmp/pidfile1.pid -fg -port 1027
 18055 pts/1    S+     0:00 grep context
fermin@neodeb:~$ cat /tmp/pidfile1.pid ; echo 
18026

i,e. the second instance has overriden the file and the reference to the first instance PID has lost.

Fix

Context Broker should check that PID file doesn't exist at the very begining (either before to check other error conditions as if the port is free). If exist, it has to exit with an error message without touching the PID file.

@fgalan
Copy link
Member Author

fgalan commented Jan 29, 2018

Fixed by PR #3091

@fgalan fgalan closed this as completed Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant