jondot / jondot/cronlock

Lock is released when cronlock exits

Open
#1 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
4
Forks
1
PR merge metrics
No merged PRs in 30d

Description

I don't understand how this tool is working. Here's an example:

```
$ (./cronlock && echo Starting A && sleep 10 && echo Finished A) &
[1] 8117
Cronlock: locked [lock.cronlock]. Returning success.
Starting A

$ (./cronlock && echo Starting B && sleep 10 && echo Finished B) &
[2] 8140
Cronlock: locked [lock.cronlock]. Returning success.
Starting B

$ (./cronlock && echo Starting C && sleep 10 && echo Finished C) &
[3] 8157
Cronlock: locked [lock.cronlock]. Returning success.
Starting C

Finished A
Finished B
Finished C

[1] Done ( ./cronlock && echo Starting A && sleep 10 && echo Finished A )
[2]- Done ( ./cronlock && echo Starting B && sleep 10 && echo Finished B )
[3]+ Done ( ./cronlock && echo Starting C && sleep 10 && echo Finished C )
```

I'd expect the second and third commands to fail.

The reason for the issue is that after the lock is acquired, the `cronlock` process is done and all its locks are released (along with file descriptors, sockets, etc.).

A solution would be to accept the command-line to run as an argument, and to run it in a sub-process. During that sub-process lifetime the lock is still taken because the `cronlock` process is still running. This is exactly the approach taken by [lockrun](http://www.unixwiz.net/tools/lockrun.html) or Linux's [flock](http://linux.die.net/man/1/flock).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at cronlock's command-line entry point and trace how it acquires and releases the lock. The change is complete when cronlock can run the supplied command while retaining the lock for that command's lifetime, and concurrent invocations fail as shown in the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.