In my production environment we have had what we believe to be a corrupt storable hash, created by Storable.pm. I am unable to replicate the behaviour in Dev, which has made it hard to diagnose exactly.
The code has been working for a long time, and the change that made it break was deleting from the hash. Up until recently, the hash either stayed the same size, or grew.
The file is opened in readwrite, and then store_fd writes to the file. As the hash is now (sometimes) smaller, it will write say 1000bytes to this 2000byte file. The tail 1000 bytes are old, garbage data. In my test cases, when I retrieve the hash, the garbage data is ignored, as expected.
open( $sf, "+< $self->{mod_state_filename}" );
flock( $sf, LOCK_EX );
$self->{mod_state} = fd_retrieve($sf);
delete ($self->{mod_state}{"somekey"});
seek( $sf, 0, 0 );
store_fd( $self->{mod_state}, $sf );
flock( $sf, LOCK_UN )
close($sf);
My questions:
I don't know how well Storable
deals with trailing garbage, but surely it can't hurt to add
truncate $sf, tell($sf);
after the call to store_fd
, eliminating all doubt about whether it can deal with it now and in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With