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
Download (untitled) / with headers
text/plain 474b
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
Download (untitled) / with headers
text/plain 193b
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?
Download (untitled) / with headers
text/plain 713b
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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.