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

not locking based on extra dots in filename #49

Open
r2evans opened this issue Jan 26, 2024 · 4 comments
Open

not locking based on extra dots in filename #49

r2evans opened this issue Jan 26, 2024 · 4 comments
Labels
reprex needs a minimal reproducible example

Comments

@r2evans
Copy link

r2evans commented Jan 26, 2024

The correctness of locking is contingent on simple file patterns.

Side-by-side, two R processes on the same host, code executed from top to bottom in order.

system("uname -a") # ubuntu 23.10
# Linux d2xps 6.5.0-14-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 14 14:59:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Sys.getpid()                                       Sys.getpid()
# [1] 278046                                       # [1] 195240

Correct behavior:

path <- "~/Downloads/quux.lock"                    path <- "~/Downloads/quux.lock"
lock <- filelock::lock(path, timeout=0)
lock
# Lock on ‘/home/r2/Downloads/quux.lock’
                                                   lock <- filelock::lock(path, timeout=0)
                                                   lock  
                                                   # NULL
filelock::unlock(lock)                             filelock::unlock(lock)
# [1] TRUE                                         # [1] TRUE

Same path, slightly different filename:

path <- "~/Downloads/quux.rds.lock"                path <- "~/Downloads/quux.rds.lock"
lock <- filelock::lock(path, timeout=0)
lock
# Lock on ‘/home/r2/Downloads/quux.rds.lock’
                                                   lock <- filelock::lock(path, timeout=0)
                                                   lock                                        
                                                   # Lock on ‘/home/r2/Downloads/quux.rds.lock’
filelock::unlock(lock)                             filelock::unlock(lock)
# [1] TRUE                                         # [1] TRUE

The underlying filesystem is local (/) and is ext4. R-4.3.2, filelock_1.0.3, in a single emacs/ess instance.

@gaborcsardi
Copy link
Member

I cannot reproduce this, unfortunately.

@gaborcsardi gaborcsardi added the reprex needs a minimal reproducible example label Jan 26, 2024
@r2evans
Copy link
Author

r2evans commented Jan 26, 2024

Interesting! I just tried using callr::r_bg and cannot reproduce it. My test above is in two processes within the same emacs/ess, do you think it's possible that somehow the process group or process-parent is confounding the logic?

@gaborcsardi
Copy link
Member

No, the fnctl(2) manual page [1] does not say anything about locks being inherited or shared. (Although they might ignore forking a process without executing another, so if you're doing that that might explain this.)

It is also very weird that this would depend on the file name.

[1] https://man7.org/linux/man-pages/man2/fcntl.2.html

@r2evans
Copy link
Author

r2evans commented Jan 26, 2024

I can't see anything in the source that would contribute to this behavior. Further ... odd ... I can no longer reproduce the behavior above. Further odd since I tested it a dozen times (same code) before starting this issue. :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants