From aa9f82fcf2a5a1586f74b0afa58ffb0bfc0cd1cb Mon Sep 17 00:00:00 2001 From: Rafael França Date: Thu, 10 Nov 2016 13:44:44 -0500 Subject: Merge pull request #1080 from sophiedeziel/master Prevent exception caused by a race condition on multi-threaded servers --- lib/rack/server.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rack/server.rb b/lib/rack/server.rb index 2253b314..2d36eb6d 100644 --- a/lib/rack/server.rb +++ b/lib/rack/server.rb @@ -1,4 +1,5 @@ require 'optparse' +require 'fileutils' module Rack @@ -352,7 +353,7 @@ module Rack def write_pid ::File.open(options[:pid], ::File::CREAT | ::File::EXCL | ::File::WRONLY ){ |f| f.write("#{Process.pid}") } - at_exit { ::File.delete(options[:pid]) if ::File.exist?(options[:pid]) } + at_exit { ::FileUtils.rm_f(options[:pid]) } rescue Errno::EEXIST check_pid! retry -- cgit v1.2.3-24-ge0c7