Coder Social home page Coder Social logo

lockfile's People

Contributors

acconut avatar asellappen avatar bitdeli-chef avatar bluele avatar coelho avatar hechuanxupt avatar nightlyone avatar oliverpool avatar renovate-bot avatar stewi1014 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lockfile's Issues

circular imports not allowed

hello, this is probably because of my inexperience with go, but when I do go get github.com/nightlyone/lockfile it says package github.com/nightlyone/lockfile imports github.com/nightlyone/lockfile: import cycle not allowed
thanks aot

Automatic retries

Have you considered adding automatic retries when obtaining the lock? I feel like it's a common enough use case where you want to wait for another process to finish before you try to access the lock. Personally, I would see it as a separate function (maybe RetryLock(retries int, sleep time.Duration))

non-recursive lock

I currently have a use-case where I need a non-recursive lock so that two subsequent lock.TryLock()s wouldn't succeed. Would you accept a patch extending the semantics? I imagine a boolean switch in Lockfile that can be used when comparing the PID of the lock owner and the current one.

return better error on Unlock/Trylock race

The motivation for the pull-request #13 from @yqylovy described an interesting observation:

when process is executing the TryLock() and another process Unlock(),the process will return a no such file or directory error

It should return a specific error here and suggest a retry. And maybe also suggest a retry in other places.

Failer on windows when pid is from dead process

os: windows (tested on win10)

Reproduce:

  1. Create lock file.
  2. Exit process without cleaning up lock file. (as happens when you crash)
  3. TryLock from new process.

This will produce OpenProcess: The parameter is incorrect. error, when it should succeed.

Cause:

func (l Lockfile) GetOwner() (*os.Process, error) {
    ...
        p, err := os.FindProcess(pid)
        if err != nil {
            return nil, err
        }
    ...
}

https://golang.org/pkg/os/#FindProcess

On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists.

But it's not documented for windows, and appears to return the error when process does not exit.

Fix:

We can assume that if the process exists, then FindProcess always succeeds in any operating system. There for, if FindProcess process returns an error, the process does not exist. So instead of returning the err, return ErrInvalidPid or ErrDeadOwner sould work here.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

gomod
go.mod
  • go 1.11

  • Check this box to trigger a request for Renovate to run again on this repository

lock failed when program restart after crash

The lockfile won't be deleted when my program crash.
And the pid in the lockfile may be reused by other process(not my program).
Then my program will be locked failed unless delete the lockfile.
System: Windows

Can lockfile check process name or path by pid ?

Documentation of algorithm constraints and fail on their violation

Without the specific atomicity guarantees of setting a hard link and rename a file in a directory the whole locking beaks. I could be more friendly to the users by documenting these constraints better and being more specific about which errors I ignore.

Also fail properly on unexpected errors when creating the hardlink.

Use symlinks instead of hardlinks on unix platforms

Hello,
first off, thanks for your library! While working on a project that uses it, I found (u-root/u-root#954) that lockfile uses hard links, and this fails if the source and the destination files are on different mount points. Hard links are not really necessary on UNIX platforms for locking purposes. If that sounds OK I will send a PR to use symlinks if the platform is a UNIX system. Thanks!

cc @hugelgupf @rminnich

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.