Permalink
Browse files

Fix a file descriptor leak in the Out-of-Band Work feature. Potential…

…ly fixes issue #864.
  • Loading branch information...
1 parent b1f91a6 commit 327cd2964b90c5dbc41d37e1c0554138056bf157 @FooBarWidget FooBarWidget committed Mar 15, 2013
Showing with 24 additions and 5 deletions.
  1. +1 −0 NEWS
  2. +3 −2 ext/common/ApplicationPool2/Implementation.cpp
  3. +20 −3 ext/common/Utils/ScopeGuard.h
View
1 NEWS
@@ -25,6 +25,7 @@ Release 4.0.0 release candidate 5
if PassengerPoolIdleTime is set to 0. Fixes issue #858.
* Fixed some process memory usage measurement bugs.
* Fixed process memory usage measurement on NetBSD. Fixes issue #736.
+ * Fixed a file descriptor leak in the Out-of-Band Work feature. Fixes issue #864.
* The PassengerPreStart helper script now uses the default Ruby
interpreter specified in the web server configuration, and no longer
requires a `ruby` command to be in `$PATH`.
@@ -562,6 +562,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
Pool::DebugSupportPtr debug = pool->debugSupport;
UPDATE_TRACE_POINT();
+ P_DEBUG("Performing OOBW request for process " << process->inspect());
if (debug != NULL && debug->oobw) {
debug->debugger->send("OOBW request about to start");
debug->messages->recv("Proceed with OOBW request");
@@ -585,7 +586,6 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
UPDATE_TRACE_POINT();
unsigned long long timeout = 1000 * 1000 * 60; // 1 min
try {
- ScopeGuard guard(boost::bind(&Socket::checkinConnection, socket, connection));
this_thread::restore_interruption ri(di);
this_thread::restore_syscall_interruption rsi(dsi);
@@ -594,7 +594,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
// need to completely read the response).
connection = socket->checkoutConnection();
connection.fail = true;
-
+ ScopeGuard guard(boost::bind(&Socket::checkinConnection, socket, connection));
// This is copied from RequestHandler when it is sending data using the
// "session" protocol.
@@ -648,6 +648,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
actions.clear();
UPDATE_TRACE_POINT();
+ P_DEBUG("Finished OOBW request for process " << process->inspect());
if (debug != NULL && debug->oobw) {
debug->debugger->send("OOBW request finished");
}
@@ -27,11 +27,14 @@
#include <boost/noncopyable.hpp>
#include <boost/function.hpp>
+#include <boost/thread.hpp>
+#include <oxt/system_calls.hpp>
#include <cstdio>
namespace Passenger {
using namespace boost;
+using namespace oxt;
#ifndef _PASSENGER_SAFELY_CLOSE_DEFINED_
@@ -48,17 +51,25 @@ using namespace boost;
class ScopeGuard: public noncopyable {
private:
function<void ()> func;
+ bool interruptable;
public:
ScopeGuard() { }
- ScopeGuard(const function<void ()> &func) {
+ ScopeGuard(const function<void ()> &func, bool interruptable = false) {
this->func = func;
+ this->interruptable = interruptable;
}
~ScopeGuard() {
if (func) {
- func();
+ if (interruptable) {
+ func();
+ } else {
+ this_thread::disable_interruption di;
+ this_thread::disable_syscall_interruption dsi;
+ func();
+ }
}
}
@@ -69,7 +80,13 @@ class ScopeGuard: public noncopyable {
void runNow() {
function<void ()> oldFunc = func;
func = function<void()>();
- oldFunc();
+ if (interruptable) {
+ oldFunc();
+ } else {
+ this_thread::disable_interruption di;
+ this_thread::disable_syscall_interruption dsi;
+ oldFunc();
+ }
}
};

0 comments on commit 327cd29

Please sign in to comment.