summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-18 15:55:41 -0700
committerJames Turnbull <james@lovedthanlost.net>2010-11-12 04:05:22 +1100
commitee61b4ecec7d5a993eac6a356b4bc0dcc6ceaf94 (patch)
treee22a9a1642abc574879a62569401adcbe990d256 /spec/unit/network
parentf57425da6aeefd4ff019068c5933add0d2a02f87 (diff)
downloadpuppet-ee61b4ecec7d5a993eac6a356b4bc0dcc6ceaf94.tar.gz
puppet-ee61b4ecec7d5a993eac6a356b4bc0dcc6ceaf94.tar.xz
puppet-ee61b4ecec7d5a993eac6a356b4bc0dcc6ceaf94.zip
Fix for #4955 -- Race condition & memory leak in Puppet::Util
The Puppet::Util.sync method was not thread safe and also leaked memory. I'm not certain, but I believe the first is ironic and the second is merely a bug. This patch addresses the problem by 1) refactoring so the sync objects are never returned (and thus no one can cache a reference to one) 2) adding reference counting 3) deleting them when they are no longer needed 4) doing the thread safty dance. It wasn't the first (or even second) solution considered, but it's the one that I was able to make work in a way that I'm convinced is correct. Its main advantage is that it puts all the tricky bits in one place.
Diffstat (limited to 'spec/unit/network')
-rwxr-xr-xspec/unit/network/server_spec.rb13
1 files changed, 3 insertions, 10 deletions
diff --git a/spec/unit/network/server_spec.rb b/spec/unit/network/server_spec.rb
index ccd9c082e..c2496dcca 100755
--- a/spec/unit/network/server_spec.rb
+++ b/spec/unit/network/server_spec.rb
@@ -5,6 +5,7 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/server'
+require 'puppet/network/handler'
describe Puppet::Network::Server do
before do
@@ -161,11 +162,7 @@ describe Puppet::Network::Server do
describe "when creating its pidfile" do
it "should use an exclusive mutex" do
Puppet.settings.expects(:value).with(:name).returns "me"
-
- sync = mock 'sync'
- Puppet::Util.expects(:sync).with("me").returns sync
-
- sync.expects(:synchronize).with(Sync::EX)
+ Puppet::Util.expects(:synchronize_on).with("me",Sync::EX)
@server.create_pidfile
end
@@ -198,11 +195,7 @@ describe Puppet::Network::Server do
describe "when removing its pidfile" do
it "should use an exclusive mutex" do
Puppet.settings.expects(:value).with(:name).returns "me"
-
- sync = mock 'sync'
- Puppet::Util.expects(:sync).with("me").returns sync
-
- sync.expects(:synchronize).with(Sync::EX)
+ Puppet::Util.expects(:synchronize_on).with("me",Sync::EX)
@server.remove_pidfile
end