Skip Menu |

This queue is for tickets about the File-Path-Tiny CPAN distribution.

Report information
The Basics
Id: 88849
Status: resolved
Priority: 0/
Queue: File-Path-Tiny

People
Owner: Nobody in particular
Requestors: e.a.bolshakova [...] yandex.ru
Cc:
AdminCc:

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



Subject: race condition issue in File::Path::Tiny + patch
Date: Sat, 21 Sep 2013 15:20:10 +0400
To: bug-file-path-tiny [...] rt.cpan.org
From: Bolshakova Elena <e.a.bolshakova [...] yandex.ru>
Hi! Here is my observation about File::Path::Tiny: if multiple processes are creating directories with same names, race condition is possible. E.g.: -d $progressive at line 16 returns false (the directory doesn't exist yet) another process creates the directory (the directory appears) mkdir( $progressive, $mask ) at line 17 returns false (the directory already exists) -- this is incorrect Easy demonstration: perl -MFile::Path::Tiny -e 'for my $i (1 .. 1000) { $path = "/tmp/file_path_tiny_test/dir_".int(rand(100000)); if ( fork() ) {File::Path::Tiny::mk($path) || print "fail\n"; wait();} else { File::Path::Tiny::mk($path) || print "fail\n"; exit;} }' |grep fail |wc -l Two processes are creating the same directories in parallel, printing 'fail' if mk returns false. These 'fail' strings are signs of collision. I usually get 20-50 collisions per 1000 iteration. I suggest additional checking of target directory existance *after* the mkdir before returning false. The same problem and suggestion applies to removing directories. I attach my patch and hope you'll accept it. -- Elena Bolshakova helena@cpan.org

Message body is not shown because sender requested not to inline it.

Subject: multi process safe File::Path::Tiny + patch
thanks! not a bad idea, I'm not totally convinced the IPC type things belong in the module or if the caller should handle that since it know the context of multiple process that may interfere with each other. I'll have to ponder it a bit :)
I added your patch to v0.8, thanks!