Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Mysterious Disapperance of file contents

by Ajnabi (Initiate)
on Aug 29, 2003 at 11:14 UTC ( [id://287627]=note: print w/replies, xml ) Need Help??


in reply to Mysterious Disapperance of file contents

I had the same problem. I suspected some sort of racing condition. It can also happen with Server or Web-Server crash.

I am taking a similar approach, but with two files in place of one. If main counter file is blank, use values from counter.bak file.


Lock Counter_File
Read Count
On Fail
Read Counter_File.bak
Increment
Write Data to Counter_File
Copy Counter_File to .bak file.
Release Lock
  • Comment on Re: Mysterious Disapperance of file contents

Replies are listed 'Best First'.
Re: Re: Mysterious Disapperance of file contents
by aquarium (Curate) on Aug 29, 2003 at 12:45 UTC
    Gorby is also chomping an array instead of just using a scalar all the way through. There's 3 opens and closes for the counterfile: first open in append, second open in RW, and third open in write. this spells disaster when not locking the lock/semaphore file properly using sysopen and flock. Therefore, when the server is busy, and the semaphore lock fails, the counter file is clobberred by another instance of the prog. It could have been written with just a single lock on the counter file itself: but locked properly (sysopen/flock) and openned and closed once, not 3 times.
      Therefore, when the server is busy, and the semaphore lock fails, the counter file is clobberred by another instance of the prog.

      No. The code says:

      flock(SEM, LOCK_EX) || die "Lock failed: $!"

      If a lock fails, the program exits, so it can't clobber.

      Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://287627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found