Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Storable - File empties itself?

by bliako (Monsignor)
on Apr 13, 2023 at 10:07 UTC ( [id://11151631]=note: print w/replies, xml ) Need Help??


in reply to Storable - File empties itself?

my $fsize = -s $storeFile; print "filesize: $fsize\n"; die if $fsize == 0;

the above will check on the filesize as the script is running from within the script.

Also store {}, $storeFile will create the file to store that empty hash(ref) but not with zero size. So if you see zero size perhaps it's coming because you are re-initialising your code and re-running the part the file is created? And/or, as hippo suggests, store may mess up if it's called at the same time on the same file from 2 different processes without file-locking. See Re: Preventing multiple instances (References on flock and running one copy of a script at a time) (random link I recall seeing lately) for file locking.

Replies are listed 'Best First'.
Re^2: Storable - File empties itself?
by feumw (Sexton) on Apr 13, 2023 at 11:54 UTC
    >> the above will check on the filesize as the script is running from within the script.
    Good idea.

    >> So if you see zero size perhaps it's coming because you are re-initialising your code and re-running the part the file is created?
    I haven't thought about this. Of course it's possible that multiple users working in the CMS might click at the same time. I'd assume that the Controller handles those but I can't make sure that there is only a single process using that file.

    I added your filesize/check as well as I added some "dies" and when I start my test-script in 2 different shells the second one immediately stops
    filesize: 9254 retrieve-error: at ../bin/store.pl line 19.
    I'll adjust out function a little and instead of die I might just let it Debug into an Logfile for now.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-17 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found