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

Should Release cleanup/delete the flockName opened by acquireFlock #8

Open
zhijianli88 opened this issue Jun 18, 2020 · 2 comments · May be fixed by #10
Open

Should Release cleanup/delete the flockName opened by acquireFlock #8

zhijianli88 opened this issue Jun 18, 2020 · 2 comments · May be fixed by #10

Comments

@zhijianli88
Copy link

Looks currently, the flockName was not cleanup after the lock is released

@zhijianli88
Copy link
Author

it leaves a lots of files in my /tmp

/tmp/juju-mk0a0e687e7de6c33cfdc2a3cefe8db8317bd821  /tmp/juju-mk5d80475b9b65e89a9878c3a723374368a83e9b  /tmp/juju-mk9d1d830eb35984af37e004fed7dcff5ec3550f  /tmp/juju-mkc9142f791142a0eb57c635c92df893f9f16181
/tmp/juju-mk4e6cec9d66a71a46fc3451716ba2209c871199  /tmp/juju-mk6d2c10f8dcb0b5b54efe777616c37992015e77  /tmp/juju-mka82cce35fd860de6f63f97e6c482dc6a14d002  /tmp/juju-mkea95ac049311d50b89f2e59ba3d9157827f30f

@zhijianli88
Copy link
Author

how about do something like below to do the cleanup:

/tmp/mutex$ git diff
diff --git a/mutex_flock.go b/mutex_flock.go
index 3708f55..76667f0 100644
--- a/mutex_flock.go
+++ b/mutex_flock.go
@@ -114,7 +114,7 @@ func acquireFlock(name string, done <-chan struct{}) <-chan acquireResult {
                        syscall.Close(fd)
                        return nil, errors.Trace(err)
                }
-               return &mutex{fd: fd}, nil
+               return &mutex{fd: fd, name: flockName}, nil
        }
        acquire := func() bool {
                releaser, err := flock()
@@ -157,8 +157,9 @@ func acquireFlock(name string, done <-chan struct{}) <-chan acquireResult {
 
 // mutex implements Releaser using the flock syscall.
 type mutex struct {
-       mu sync.Mutex
-       fd int
+       mu   sync.Mutex
+       fd   int
+       name string
 }
 
 // Release is part of the Releaser interface.
@@ -173,6 +174,7 @@ func (m *mutex) Release() {
                panic(err)
        }
        m.fd = 0
+       os.Remove(m.name)
 }
 
 // Environment defines a simple interface with interacting with environmental

@ghost ghost linked a pull request Oct 18, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant