From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.mongrel.devel Subject: [PATCH] always set FD_CLOEXEC on sockets post-accept() Date: Thu, 9 Jul 2009 02:56:24 -0700 Message-ID: <20090709095624.GA2805@dcvr.yhbt.net> Reply-To: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1247133463 18605 80.91.229.12 (9 Jul 2009 09:57:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Jul 2009 09:57:43 +0000 (UTC) To: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Original-X-From: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Thu Jul 09 11:57:36 2009 Return-path: Envelope-to: gclrmd-mongrel-development@m.gmane.org Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-BeenThere: mongrel-development-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: mongrel-development-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.mongrel.devel:141 Archived-At: Received: from rubyforge.org ([205.234.109.19]) by lo.gmane.org with esmtp (Exim 4.50) id 1MOqNk-0000qb-3Q for gclrmd-mongrel-development@m.gmane.org; Thu, 09 Jul 2009 11:57:36 +0200 Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id E7BCA1779931; Thu, 9 Jul 2009 05:57:29 -0400 (EDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 28AB118580E4 for ; Thu, 9 Jul 2009 05:56:25 -0400 (EDT) Received: from localhost (user-118bg0q.cable.mindspring.com [66.133.192.26]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id ECE991F5FC; Thu, 9 Jul 2009 09:56:24 +0000 (UTC) List-Post: FD_CLOEXEC is not guaranteed to be inherited by the accept()-ed descriptors even if the listener socket has this set. This can be a problem with applications that fork+exec long running background processes and our client expects us to close a connection to signal a completed response: the connection would only be closed when the background process closed it (when it exited), not when Mongrel closes the socket. This issue was discovered with a server other than Mongrel but the issue here is applicable to Mongrel as well. --- This patch was based on the below branch (against c365ba16d12a14bdf1cc50a26f67dd3b45f5a4d8) > I used git-svn and added it to > http://github.com/fauna/mongrel/tree/trunk_from_svn, where it can lie > unchanged for reference. P.S.: I know I used to have a commit bit to the Mongrel SVN but I never really cared for it since I've always preferred the mailing-patches-around-for-review form of development. Let me know if pushing things to git://git.bogomips.org/mongrel.git for you to pull is preferable in the future. P.P.S: not sure if it's common around here, but I've long had mutt setup to pipe messages to "git am" directly from the index or pager and also diff syntax hilighting in the mutt pager. It all makes patch review/testing *much* nicer without having to context switch out of a terminal/screen. lib/mongrel.rb | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/lib/mongrel.rb b/lib/mongrel.rb index f09a617..0619abe 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -278,7 +278,11 @@ module Mongrel if defined?($tcp_cork_opts) and $tcp_cork_opts client.setsockopt(*$tcp_cork_opts) rescue nil end - + + if defined?(Fcntl::FD_CLOEXEC) + client.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + end + worker_list = @workers.list if worker_list.length >= @num_processors -- Eric Wong