cocaine/cocaine-core

Clean-up configured "runtime" directory

mwf opened this issue · 2 comments

mwf commented

Hi!

I'd like to propose such thing - clean-up configured "runtime" directory on cocaine-runtime process start.

I've got a situation, when cocaine-runtime had not been terminated properly - there was a server power-loss. So all files "< app-name >.< pid >" in "runtime" directory were not deleted! And after server boot cocaine-runtime process randomly got just the same PID as it had before the power loss!

I think you can imagine what happened next...

[Tue Sep  2 18:05:34 2014] [ERROR] service/node: unable to start the 'bio_auth' app - unable to initialize the engine - unable to bind an acceptor on '/usr/local/var/run/cocaine/bio_auth.121': Address already in use - [48] Address already in use

Runlist can't be started unless I restart cocaine-runtime manually (and get new PID) or clean-up the directory...

We've been thinking about it at some point and decided to go with the <app_name.pid> scheme instead of cleaning up the directory (it was simply <app_name> before that). Imagine that you start another instance of cocaine-runtime by mistake, while the first one is doing something — the new instance will clean the run directory, effectively killing all the running apps. There's no way to tell stale and normal socket files apart, and removing everything is a bad idea. What we can do, though, is to remove socket files with the same pid part as our pid if we see them on start, because they are obviously stale.

mwf commented

Yeah, removing files with the same pid is a suitable solution.

It would be great to get the fix in v0.11 branch =)