We had a service provider during a project and one of them built a feature calles "Userlist and Useraction". This has two parts. There is an overview "Userlist" where we can see the userid + timestamp (last time he was active). This "Userlist" just reads the Perl-Storage. The second part is the "Useraction" which is a Controller in our CMS which is called whenever a user does anything. This "Useraction" retrieves the Perl-Storage and stores username + timestamp.

Our issue is that sometimes (randomly) this Perl-Storage seems to be cleared. When we do stat on the file, only the "modified" changed. So the file does not get deleted. But it seems like it's loosing all it's content. Apparently it seems to be like once a month. We made sure there were no updates/backups or anything at this time of the day.

Since this is built into our CMS i can only try to provide parts of the code.

Userlist.PM
use Storable; use Time::Local; sub go { my $storeFile = '/db/users.store'; my $usersFile = (); if ( -e $storeFile ) { $usersFile = retrieve( $storeFile ); } # Do stuff and return me a precious overview of all my userids and + their timestamps # # userid | timestamp # 1337 | Fri Dec 16 12:11:43 2022 # 1234 | ri Jan 20 09:21:36 2023 # ... }
Useraction.PM
use Storable; sub go : Path { my $user = $common->{user}; # CMS Stuff: Get the curre +nt logged in user my $uid = $user->getInfo()->{id}; # CMS Stuff: Get his useri +d my $storeFile = '/db/users.store'; my $ts = localtime( time ); my $users = (); if (-e $storeFile) { $users = retrieve( $storeFile ); } $users->{$uid} = $ts; store $users, $storeFile; }

Is there any chance that the Module has some kind of issue if only using store and retrieve? On https://perldoc.perl.org/Storable I read something about recursion limitations. This could be the reason why we're having the issue once every month. We might reach the limitation after 1 month. I'm clueless right now what could be the issue here.

I tried to reproduce the error by copying one of our files and use the following script:

my $storeFile = "/db/users.store.test"; my $users = (); my $ts; for (my $i = 0; $i < 2000; $i++){ $users = retrieve( $storeFile ); $ts = localtime( time ); foreach my $KEY ( keys % { $users } ){ print "#" . $KEY . "#" . $ts . "#\n"; $users->{$KEY} = $ts; store $users, $storeFile; } usleep(250); }

And while the script is running and chaning the file i do ls -l on a second shell and sometimes the file will be set to 0KB.

Example File can be downloaded from my BSCW (Basic Support for Cooperative Work) Cloud


In reply to Storable - File empties itself? by feumw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.