Brad Fitzpatrick (brad) wrote,
Brad Fitzpatrick
brad

today's rage #1: portable advisory file locking

So at work we made this little network lock daemon, and client that's capable of using them all (or all that are alive) to take out locks. Tiny, tiny, works great.

So then we're like, "Oh, we need a dumb fallback method for people on single hosts. Let's just do flock or fnctl or lockf or something.... that'll be easy...."

Yeah, right.

Either we're all crazy, or flock/fnctl/lockf are a total pain in the ass. Our lock stress tester (10 forked children fighting for a few seconds over a small number of locks) works perfectly with our network lock client/daemon..... the synchronized code (an O_CREAT|O_EXCL open + unlink) never fails.

But once we switch to using local-machine locking, reliability goes to hell.

What's wrong here?
http://www.danga.com/temp/flock-test.c

It seems both fcntl and flock locks are released at different times, but I can't get it right. It only works if I comment out the line after BIZARRE in the source above. (never unlinking the file I flock)

Where's the race?
Subscribe

  • Contributing to Open Source projects

    Prior to joining Google I always joked that Google was the black hole that swallowed up open source programmers. I'd see awesome, productive hackers…

  • Realtime LiveJournal -> Buzz

    If you've seen all my "test" posts over the past few days, you probably knew I was up to something. Indeed.... If you add your LiveJournal to your…

  • Google Profiles has XFN now

    Google Profiles just launched a new feature that's too dorky and obscure to warrant an official "Google blog" blog post, so the product manager on…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 19 comments

  • Contributing to Open Source projects

    Prior to joining Google I always joked that Google was the black hole that swallowed up open source programmers. I'd see awesome, productive hackers…

  • Realtime LiveJournal -> Buzz

    If you've seen all my "test" posts over the past few days, you probably knew I was up to something. Indeed.... If you add your LiveJournal to your…

  • Google Profiles has XFN now

    Google Profiles just launched a new feature that's too dorky and obscure to warrant an official "Google blog" blog post, so the product manager on…