diff options
| author | Markus Roberts <Markus@reality.com> | 2010-10-18 15:55:41 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2010-11-12 04:05:22 +1100 |
| commit | ee61b4ecec7d5a993eac6a356b4bc0dcc6ceaf94 (patch) | |
| tree | e22a9a1642abc574879a62569401adcbe990d256 /lib/puppet/network | |
| parent | f57425da6aeefd4ff019068c5933add0d2a02f87 (diff) | |
| download | puppet-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 'lib/puppet/network')
| -rw-r--r-- | lib/puppet/network/server.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb index d424b9c4a..e4de07dea 100644 --- a/lib/puppet/network/server.rb +++ b/lib/puppet/network/server.rb @@ -32,14 +32,14 @@ class Puppet::Network::Server # Create a pidfile for our daemon, so we can be stopped and others # don't try to start. def create_pidfile - Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do + Puppet::Util.synchronize_on(Puppet[:name],Sync::EX) do raise "Could not create PID file: #{pidfile}" unless Puppet::Util::Pidlock.new(pidfile).lock end end # Remove the pid file for our daemon. def remove_pidfile - Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do + Puppet::Util.synchronize_on(Puppet[:name],Sync::EX) do locker = Puppet::Util::Pidlock.new(pidfile) locker.unlock or Puppet.err "Could not remove PID file #{pidfile}" if locker.locked? end |
