public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Cyril Bonté" <cyril.bonte@free.fr>
To: netdev@vger.kernel.org
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Daniel Baluta <daniel.baluta@gmail.com>,
	Gaspar Chilingarov <gasparch@gmail.com>,
	Charles Duffy <charles@dyfis.net>, Willy Tarreau <w@1wt.eu>
Subject: tcp: disallow bind() to reuse addr/port regression in 2.6.38
Date: Sat, 2 Apr 2011 20:01:47 +0200	[thread overview]
Message-ID: <201104022001.48144.cyril.bonte@free.fr> (raw)

Hi All,

(2nd try to fix the mailing list address)

It has been reported that kernel 2.6.38 prevented the load balancer haproxy to 
reload. After reading the kernel Changelog, it looks like the following commit 
has a negative side effect on the the way haproxy "pauses" its listening 
sockets to start a new process :

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=c191a836a908d1dd6b40c503741f91b914de3348

Disabling the TCPF_CLOSE flag condition reallows to work as before. I guess 
this was done for good reasons (Sorry, I haven't found the thread about that 
commit in the archives yet) but other applications may also be impacted by 
this change.

I add Willy Tarreau to the CC to open the discussion.

Here is a simple test case to reproduce the issue (with kernel 2.6.38, it will 
fail on the second loop whereas it works with previous kernel versions) :
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>

int main(int argc, char**argv)
{
	int listenfd;
	struct sockaddr_in servaddr;
	int i;
	int one = 1;
	
	for (i = 0; i < 2; i++)
	{
		printf("LOOP %d...\n", i + 1);
		listenfd=socket(AF_INET,SOCK_STREAM,0);

		setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));

		bzero(&servaddr,sizeof(servaddr));
		servaddr.sin_family = AF_INET;
		servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
		servaddr.sin_port=htons(32000);

		if (bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr)) != 0)
		{
			perror("bind");
			exit(1);
		}

		if (listen(listenfd,1024) != 0)
		{
			perror("listen");
			exit(1);
		}

		if (shutdown(listenfd, SHUT_WR) == 0 &&
		    listen(listenfd, 1024) == 0 &&
		    shutdown(listenfd, SHUT_RD) == 0) {
			printf("shutdown OK\n");
		}
	}
	exit(0);
}

-- 
Cyril Bonté

             reply	other threads:[~2011-04-02 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-02 18:01 Cyril Bonté [this message]
2011-04-02 18:10 ` tcp: disallow bind() to reuse addr/port regression in 2.6.38 Eric Dumazet
2011-04-02 18:46   ` Cyril Bonté
2011-04-02 19:15     ` Willy Tarreau
2011-04-02 19:44       ` Eric Dumazet
2011-04-02 20:37         ` Willy Tarreau
2011-04-02 21:00           ` Cyril Bonté
2011-04-02 21:18             ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201104022001.48144.cyril.bonte@free.fr \
    --to=cyril.bonte@free.fr \
    --cc=charles@dyfis.net \
    --cc=daniel.baluta@gmail.com \
    --cc=eric.dumazet@gmail.com \
    --cc=gasparch@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox