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

speedtables startup locking sometimes fails to provide mutual exclusion / fails outright #49

Closed
mutability opened this issue Dec 2, 2015 · 4 comments
Assignees

Comments

@mutability
Copy link

If you start up a few separate processes concurrently that share the same table definition (and working area) sometimes the locking during table init fails outright like this:

error deleting "/var/tmp/adsb/c_aircraft_registry_faa.lock.lock": no such file or directory
    while executing
"file delete $name.lock"
    (procedure "unlockfile" line 20)
    invoked from within
"unlockfile $lockfile"
    (procedure "lockfile" line 71)
    invoked from within
"lockfile $build_dir err"
    (procedure "::stapi::init_ctable" line 30)
    invoked from within
"::stapi::init_ctable aircraft_registry_faa "" "modescode IS NOT NULL AND active IS TRUE" modescode nnumber"
    (procedure "create_stapi_tables" line 12)
    invoked from within
"create_stapi_tables"
    (procedure "main" line 88)
    invoked from within

Additionally, sometimes in the same sort of situation, compilation will fail with bizarre errors because there are two processes trying to compile in the same place (i.e. the locking is not providing mutual exclusion).

@mutability
Copy link
Author

It looks like lockfile is fundamentally broken. It assumes that tcl's "file rename" without -force is atomic, i.e. it will either rename the file without clobbering, or fail.

This is not true. It first checks if the target exists. If the target does not exist, then it does a rename() call, which atomically replaces the target if it exists. There is a window between the test and the rename where another process could create the lockfile.

I'd suggest just using TclX's "flock" (open the lockfile in a+ mode, try to flock -nowait, keep the lockfile open until you want to release the lock)

@mutability
Copy link
Author

or you could probably do something with opening the lockfile with flags CREAT EXCL

@resuna resuna self-assigned this Mar 27, 2016
@resuna
Copy link
Member

resuna commented Apr 4, 2016

I've created a "locking" branch off "stapi-test" to work on this. Creating the lockfile directly creates a potential race condition where the lockfile is created but the PID of the opener hasn't been put into it. I think I've handled that. Can you give it a try?

@bovine
Copy link
Member

bovine commented Jun 28, 2016

Fixed in 1.6.4 release.

@bovine bovine closed this as completed Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants