From owner-freebsd-java@FreeBSD.ORG Sat Feb 18 20:46:01 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3EBB216A420 for ; Sat, 18 Feb 2006 20:46:01 +0000 (GMT) (envelope-from arnej@pvv.ntnu.no) Received: from decibel.pvv.ntnu.no (decibel.pvv.ntnu.no [129.241.210.179]) by mx1.FreeBSD.org (Postfix) with SMTP id 742D443D45 for ; Sat, 18 Feb 2006 20:45:58 +0000 (GMT) (envelope-from arnej@pvv.ntnu.no) Received: (qmail 8723 invoked by uid 27959); 18 Feb 2006 20:45:57 -0000 Date: Sat, 18 Feb 2006 21:45:57 +0100 (CET) From: "Arne H. Juul" To: Nate Williams In-Reply-To: <17399.20883.741021.688682@caddis.yogotech.com> Message-ID: References: <43F4F22F.1060402@europe.yahoo-inc.com> <200602171054.11632.lists@intricatesoftware.com> <43F72599.4030009@intricatesoftware.com> <17399.20883.741021.688682@caddis.yogotech.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-java@freebsd.org, Kurt Miller Subject: Re: SO_REUSEADDR should not also mean SO_REUSEPORT X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Feb 2006 20:46:01 -0000 On Sat, 18 Feb 2006, Nate Williams wrote: >> Ok, thanks. I got that impression from reading some posts I found >> while googling. There was one in particular for NetBSD that >> discussed it in detail. Check out the Apr 2 portion of this >> http://www.tinyurl.com/b46gq by Jan Schaumann. Also this >> one http://tinyurl.com/9sa6a. From these posts it appears >> that SO_REUSEPORT is needed in some cases to be compatible >> with linux. > >> From the early days.... > > - In the Multicast constructor, the low level routine sets the > SO_REUSEADDR option by using JSO_REUSEADDR which corresponds to a call > to setsockopt(..SO_REUSEADDR). To make multicast sockets work in *all* > cases on FreeBSD, we should also set SO_REUSEPORT, else in many cases > the multicast bind will fail. I won't claim to know what's the best behaviour with multicast, but the problem is that SO_REUSEPORT is always used when SO_REUSEADDR was requested, meaning that: > SO_REUSEPORT allows completely duplicate bindings by multiple > processes if they all set SO_REUSEPORT before binding the port. so you can have two very different java servers listening on the same port, for example. Or the same java server started twice won't notice any problem because the second instance will bind its server port fine, while on all other OSes this would give a sensible error message. And so on. This is bad. The reason I found this problem in the first place was from a Java program that worked well on Linux, not at all on FreeBSD, and after much tracing we deduced that something was enabling SO_REUSEPORT on FreeBSD, after which finding the bad code was a simple matter of "grep", only leaving the question of why it was there in the first place. If anybody figures out what's best practice for supporting multicast applications, ask the BSD kernel people to change the kernel behaviour to match best practice, make it possible to control SO_REUSEPORT from the MulticastSocket class, or find some other solution that doesn't make *other* types of java application suffer. - Arne H. J.