Stop overwriting existing pidfiles. #505

Merged
merged 1 commit into from Feb 7, 2013

Projects

None yet

3 participants

@TimMoore

A race condition can arise when two servers are started simultaneously. Both
instances may complete the check for an existing pidfile before either one
writes it.

Now the pidfile is opened with ::File::EXCL, which raises an error if the file
already exists. This error is handled by retrying the check and the write.

@TimMoore TimMoore Stop overwriting existing pidfiles.
A race condition can arise when two servers are started simultaneously. Both
instances may complete the check for an existing pidfile before either one
writes it.

Now the pidfile is opened with ::File::EXCL, which raises an error if the file
already exists. This error is handled by retrying the check and the write.
85b50e2
@raggi
Official Rack repositories member

What is the value of File::EXCL on windows, and is it a valid argument?

@TimMoore

That's a good question. I don't have a Windows box to test on. This should probably go through some cross-platform testing before merging. I think running rake fulltest should be sufficient.

@raggi raggi merged commit e6b70a7 into rack:master Feb 7, 2013

1 check failed

Details default The Travis build could not complete due to an error
@raggi
Official Rack repositories member

Thanks!

@TimMoore

Thanks for merging. Did you find an answer to the question about Windows support?

@raggi
Official Rack repositories member

The constant is defined there. I haven't checked semantics, but I've asked Luis to take a look at our test suites over there.

@TimMoore TimMoore deleted the TimMoore:pidfile-create-exclusive branch Feb 11, 2013
@TimMoore TimMoore deleted the TimMoore:pidfile-create-exclusive branch Feb 11, 2013
@tcandrew7

I am unable to start multiple rails processes using the following command:

rails s -b <my ip> -p 8080 &
export USER_ID=3 && rails s -b <my ip> -p 3001 &
export USER_ID=4 && rails s -b <my ip> -p 3002 &
export USER_ID=49 && rails s -b <my ip> -p 5001 &
export USER_ID=160 && rails s -b <my ip> -p 5003 &

This is the error I am seeing:

/usr/local/rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.5/lib/rack/server.rb:332:in delete': No such file or directory - /home/<myuser>/<myproject>/tmp/pids/server.pid (Errno::ENOENT)
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.5/lib/rack/server.rb:332:in
check_pid!'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.5/lib/rack/server.rb:250:in start'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in
start'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/commands.rb:55:in block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/commands.rb:50:in
tap'
from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/commands.rb:50:in <top (required)>'
from script/rails:6:in
require'
from script/rails:6:in `

'

I am running on CentOS 6 with ruby 1.9.3p327, rails 3.2.8, and rack 1.4.5.

@TimMoore

@tcandrew7 I think that's a result of the bug that was fixed by this pull request. It was released in Rack 1.5.2.

When you run 'rails server' (or 'rails s') it sets the pidfile to ./tmp/pids/server.pid. This means that with the changes in Rack 1.4.2 and 1.5.2 to avoid overwriting pidfiles, you can only start multiple Rails servers if you tell it to use a different pidfile for each one. Try this:

rails s -b <my ip> -p 8080 &
export USER_ID=3 && rails s -b <my ip> -p 3001 -P `pwd`/tmp/pids/server-3001.pid &
export USER_ID=4 && rails s -b <my ip> -p 3002 -P `pwd`/tmp/pids/server-3002.pid &
export USER_ID=49 && rails s -b <my ip> -p 5001 -P `pwd`/tmp/pids/server-5001.pid &
export USER_ID=160 && rails s -b <my ip> -p 5003 -P `pwd`/tmp/pids/server-5003.pid &

The -P flag specifies a different file for each server instance. The name can be anything that doesn't conflict, but it has to be an absolute path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment