Skip Menu |

This queue is for tickets about the Config-Std CPAN distribution.

Report information
The Basics
Id: 82190
Status: open
Priority: 0/
Queue: Config-Std

People
Owner: Nobody in particular
Requestors: victor [...] vsespb.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Flock and open for writing race condition
It looks to me that this code open my $fh, '>', $filename or croak "Can't open config file '$filename' for writing (\L$!\E)"; flock($fh,LOCK_EX|LOCK_NB) || croak "Can't write to locked config file '$filename'" if ! ref $filename; will actually destroy file before croak 'Can't write to locked config file' AFAIK, open in not distructive read/write mode + flock + seek + truncate is advised here - http://www.perlmonks.org/index.pl?node_id=7058
RT-Send-CC: DCONWAY [...] cpan.org, TMETRO [...] cpan.org
thank you for your thoughtful report with reference to best practice to remedy. Fixing this may become the entertainment for Boston.PM next meeting :-) Making a test for this will be hard?
On Mon Dec 24 03:53:40 2012, BRICKER wrote: Show quoted text
> thank you for your thoughtful report with reference to best practice to > remedy. Fixing this may become the entertainment for Boston.PM next > meeting :-) Making a test for this will be hard?
I think to test this, need only mock "open" and "flock" and make sure it's called with right params. Real integration test is of course hard :) But if you want to do it for fun, you can insert between open and flock a code, which gets executed only in unit test. This code will try open same file (not sure how, maybe dup a handle or just same filename) and write something to it. Then, after error message that file is locked, you can check that it's not destroyed.