Re: [BUG] net.jini.jeri.tcp.TcpServerEndpoint$LH$ServerConnectionImpl

Peter Jones <[email protected]>
Newsgroups gmane.comp.java.sun.jini
Message-ID <20070502220930.GP11978@east>
On Wed, May 02, 2007 at 10:48:38PM +0200, Mark Brouwer wrote:
> Peter Jones - JavaSoft East wrote:
> >>>>>And this bug has already been filed:
> >>>>>
> >>>>>    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4720952
> >>>>Thanks for sorting out, I did a very very quick search at the bug
> >>>>database but didn't find anything that made me believe there was a bug,
> >>>>given my interpretation that a closed socket is not connected. I hope
> >>>>that your time isn't waisted by me filing a bug against the JTSK and
> >>>>that you can use this 'customer case' as an extra way of forcing the
> >>>>J2SE team to have this bug closed before it exceeds the 2 years :-(
> >>>It is certainly helpful for us to learn about this (I hadn't been
> >>>aware of this bug before); thanks again for the report,
> >>Peter,
> >>
> >>While this is a bug or a documentation issue in the Sun JVMs, it has not
> >>been fixed/documented yet and probably won't before I retire (sorry I
> >>can get a bit pessimistic these days) and we do run into this issue at
> >>regular times. It is not harmful but we do get questions from customers
> >>that get scared by seeing unchecked exceptions in their log files and I
> >>don't blame them.
> >>
> >>I wonder whether the Porter release can handle socket.getInetAddress()
> >>returning null in cases where it can be expected based on the above bug
> >>report. If so it would be really great!
> >
> >It is indeed unfortunate to scare customers with unchecked exceptions;
> >yes, I think that we can do that for Porter (although probably not for
> >Beta).  I have filed it as an RFE:
> >
> >      http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6243057
>
> As 4720952 is still in progress and the problem described in this thread
> occurs more often as one would like to see (see attachment) I want to
> fix this.
>
> Peter could you indicate what you think the behavior should be in case
> socket.getInetAddress() returns null, so I can start fixing this. Do you
> envision caching the result of socket.getInetAddress() or just return
> when it resolves to null as you will get an exception at a different
> level anyway.

For 6243057 (fixed in Porter) we added a workaround for 4720952 by
caching the result of socket.getInetAddress()-- see diffs appended
below-- but only for TcpServerEndpoint, and from your stack trace it
appears that you are now encountering the equivalent issue on the
client side.  I think that an equivalent workaround in TcpEndpoint
would be reasonable-- when the TcpEndpoint.ConnectionImpl constructor
is invoked the socket will not have been exposed to any code that
could close it-- although you would (just) need to cache the result of
socket.getRemoteSocketAddress() instead of socket.getInetAddress().

-- Peter

--- TcpServerEndpoint.java@@/main/56    Wed Feb  9 15:06:35 2005
+++ TcpServerEndpoint.java@@/main/57    Wed May 11 18:23:12 2005
@@ -969,8 +969,14 @@

            private final Socket socket;

+           // socket attributes cached to work around 4720952:
+           private final InetAddress socketInetAddress;
+           private final int socketPort;
+
            ServerConnectionImpl(Socket socket) {
                this.socket = socket;
+               socketInetAddress = socket.getInetAddress();
+               socketPort = socket.getPort();
                addToConnectionSet();
            }

@@ -995,8 +1001,8 @@
            public void checkPermissions(InboundRequestHandle handle) {
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
-                   sm.checkAccept(socket.getInetAddress().getHostAddress(),
-                                  socket.getPort());
+                   sm.checkAccept(socketInetAddress.getHostAddress(),
+                                  socketPort);
                }
            }

@@ -1020,7 +1026,7 @@
            public void populateContext(InboundRequestHandle handle,
                                        Collection context)
            {
-               Util.populateContext(context, socket.getInetAddress());
+               Util.populateContext(context, socketInetAddress);
            }

            public void close() {

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.