> On 16 January 2013 19:39, Roberto De Ioris <[email protected]> wrote: >> >>> I actually found that flock has, for some reason, no effect whatsoever >>> when daemonize is used. (Is that fd inadvertently closed?) >>> >>> This is on an ext4 filesystem. The related test configs: (the asdf >>> lockfile was pre-created) >>> >>> $ cat x.ini >>> [uwsgi] >>> flock=asdf >>> socket=/tmp/test.sock >>> daemonize=foo.log >>> >>> $ cat x-nodaemon.ini >>> [uwsgi] >>> flock=asdf >>> socket=/tmp/test.sock >>> >>> First session, showing two daemonized uWSGIs and one non-daemonized >>> uWSGI >>> starting concurrently with the same flock file: >>> >>> $ uwsgi-1.4.3 x.ini >>> [uWSGI] getting INI configuration from x.ini >>> >>> $ uwsgi-1.4.3 x.ini >>> [uWSGI] getting INI configuration from x.ini >>> >>> $ ps aux | grep x.ini >>> 21943 ... uwsgi-1.4.3 x.ini >>> 21947 ... uwsgi-1.4.3 x.ini >>> >>> $ uwsgi-1.4.3 x-nodaemon.ini >>> [uWSGI] getting INI configuration from x-nodaemon.ini >>> *** Starting uWSGI 1.4.3 (64bit) on [Tue Jan 15 09:50:39 2013] *** >>> >>> And a second session, with two non-daemonized uWSGIs with the same >>> lockfile: >>> >>> (shell 1) $ uwsgi-1.4.3 x-nodaemon.ini >>> [uWSGI] getting INI configuration from x-nodaemon.ini >>> *** Starting uWSGI 1.4.3 (64bit) on [Tue Jan 15 09:51:23 2013] *** >>> >>> (shell 2) $ uwsgi-1.4.3 x-nodaemon.ini >>> [uWSGI] getting INI configuration from x-nodaemon.ini >>> uWSGI ERROR: asdf is locked by another instance >>> (shell 2) $ >>> >>> Strange... >>> >>> - >> >> it is the expected behaviour. >> >> If you fork() after a flock(), the lock is lost. > > This is confusing. The flock(2) manpage says the opposite: > > <quote> > Locks created by flock() are associated with an open file table entry. > This means that duplicate file descriptors (created by, for > example, fork(2) or dup(2)) refer to the same lock, and this lock may > be modified or released using any of these descriptors. Furthermore, > the lock is released either by an explicit LOCK_UN operation on any of > these duplicate descriptors, or when all such descriptors have > been closed. > </quote> > > I regularly flock and fork and do not lose the lock in child > processes. Generally in Perl, but whatever, it uses fork(), and > flock() internally. > > What am I missing? Are you describing uWSGI specific behavior? >
it is a "daemonization" behaviour, but it is not clear if it is linux specific. basically: flock() on proc 1 fork() on proc 1 proc 2 starts exit() on proc 1 the lock is released in proc2 If you do not exit the main process the lock is ok -- Roberto De Ioris http://unbit.it _______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
