Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ly fixes issue #864.
  • Loading branch information...
commit 327cd2964b90c5dbc41d37e1c0554138056bf157 1 parent b1f91a6
Hongli Lai authored March 15, 2013
1  NEWS
@@ -25,6 +25,7 @@ Release 4.0.0 release candidate 5
25 25
    if PassengerPoolIdleTime is set to 0. Fixes issue #858.
26 26
  * Fixed some process memory usage measurement bugs.
27 27
  * Fixed process memory usage measurement on NetBSD. Fixes issue #736.
  28
+ * Fixed a file descriptor leak in the Out-of-Band Work feature. Fixes issue #864.
28 29
  * The PassengerPreStart helper script now uses the default Ruby
29 30
    interpreter specified in the web server configuration, and no longer
30 31
    requires a `ruby` command to be in `$PATH`.
5  ext/common/ApplicationPool2/Implementation.cpp
@@ -562,6 +562,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
562 562
 	Pool::DebugSupportPtr debug = pool->debugSupport;
563 563
 
564 564
 	UPDATE_TRACE_POINT();
  565
+	P_DEBUG("Performing OOBW request for process " << process->inspect());
565 566
 	if (debug != NULL && debug->oobw) {
566 567
 		debug->debugger->send("OOBW request about to start");
567 568
 		debug->messages->recv("Proceed with OOBW request");
@@ -585,7 +586,6 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
585 586
 	UPDATE_TRACE_POINT();
586 587
 	unsigned long long timeout = 1000 * 1000 * 60; // 1 min
587 588
 	try {
588  
-		ScopeGuard guard(boost::bind(&Socket::checkinConnection, socket, connection));
589 589
 		this_thread::restore_interruption ri(di);
590 590
 		this_thread::restore_syscall_interruption rsi(dsi);
591 591
 
@@ -594,7 +594,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
594 594
 		// need to completely read the response).
595 595
 		connection = socket->checkoutConnection();
596 596
 		connection.fail = true;
597  
-		
  597
+		ScopeGuard guard(boost::bind(&Socket::checkinConnection, socket, connection));
598 598
 		
599 599
 		// This is copied from RequestHandler when it is sending data using the
600 600
 		// "session" protocol.
@@ -648,6 +648,7 @@ Group::spawnThreadOOBWRequest(GroupPtr self, ProcessPtr process) {
648 648
 	actions.clear();
649 649
 
650 650
 	UPDATE_TRACE_POINT();
  651
+	P_DEBUG("Finished OOBW request for process " << process->inspect());
651 652
 	if (debug != NULL && debug->oobw) {
652 653
 		debug->debugger->send("OOBW request finished");
653 654
 	}
23  ext/common/Utils/ScopeGuard.h
@@ -27,11 +27,14 @@
27 27
 
28 28
 #include <boost/noncopyable.hpp>
29 29
 #include <boost/function.hpp>
  30
+#include <boost/thread.hpp>
  31
+#include <oxt/system_calls.hpp>
30 32
 #include <cstdio>
31 33
 
32 34
 namespace Passenger {
33 35
 
34 36
 using namespace boost;
  37
+using namespace oxt;
35 38
 
36 39
 
37 40
 #ifndef _PASSENGER_SAFELY_CLOSE_DEFINED_
@@ -48,17 +51,25 @@ using namespace boost;
48 51
 class ScopeGuard: public noncopyable {
49 52
 private:
50 53
 	function<void ()> func;
  54
+	bool interruptable;
51 55
 	
52 56
 public:
53 57
 	ScopeGuard() { }
54 58
 	
55  
-	ScopeGuard(const function<void ()> &func) {
  59
+	ScopeGuard(const function<void ()> &func, bool interruptable = false) {
56 60
 		this->func = func;
  61
+		this->interruptable = interruptable;
57 62
 	}
58 63
 	
59 64
 	~ScopeGuard() {
60 65
 		if (func) {
61  
-			func();
  66
+			if (interruptable) {
  67
+				func();
  68
+			} else {
  69
+				this_thread::disable_interruption di;
  70
+				this_thread::disable_syscall_interruption dsi;
  71
+				func();
  72
+			}
62 73
 		}
63 74
 	}
64 75
 	
@@ -69,7 +80,13 @@ class ScopeGuard: public noncopyable {
69 80
 	void runNow() {
70 81
 		function<void ()> oldFunc = func;
71 82
 		func = function<void()>();
72  
-		oldFunc();
  83
+		if (interruptable) {
  84
+			oldFunc();
  85
+		} else {
  86
+			this_thread::disable_interruption di;
  87
+			this_thread::disable_syscall_interruption dsi;
  88
+			oldFunc();
  89
+		}
73 90
 	}
74 91
 };
75 92
 

0 notes on commit 327cd29

Please sign in to comment.
Something went wrong with that request. Please try again.