harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Loats (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-5530) Selector.select() returns exception if network connection is lost
Date Wed, 20 Feb 2008 22:59:50 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-5530?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12570876#action_12570876
] 

Phil Loats commented on HARMONY-5530:
-------------------------------------

Looking at the source code, 
SelectorImpl.java uses a Pipe for the Mock channel...
  this pipe is implemented using SocketChannels and the sockets are connected using InetAddress.getLocalHost().

Normally InetAddress.getLocalHost() returns the windows configured IP address(e.g. 192.168.0.100).
 When there is no windows configured IP address, it returns 127.0.0.1 (localhost).  

Chaning the socketBind and finishConnect in SinkChannelImpl and SourceChannelImpl from InetAddress.getLocalHost()
to Inetaddress.getByName("127.0.0.1"), does resolve the testcase issue on windows.  Seems
also safe on linux.

Any comment on how safe this change would be to make?

> Selector.select() returns exception if network connection is lost
> -----------------------------------------------------------------
>
>                 Key: HARMONY-5530
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5530
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>    Affects Versions: 5.0M4
>         Environment: Only test on Win32, Linux unknown at this time.
>            Reporter: Phil Loats
>
> This problem was seen on version "harmony-jdk-603534"
> When Selector.select() is called with an empty list, then the network connection is lost
- an exception is thrown to the caller.
> This behavior is different from J2SE 1.5 where it continues to wait without throwing
an exception.
> The following test code will show this problem:
> import java.io.IOException;
> import java.nio.channels.Selector;
> public class Test {
> 	public static void main(String[] args) {
> 		Selector selector = null;
> 		
> 		try {
> 			selector = Selector.open();
> 			System.out.println("selector open...");		       
> 		} catch (IOException e) {
> 	    }
> 		    
> 		// Wait for events
> 		while (true) {
> 		    try {
> 		    	// Wait for an event
> 		    	System.out.println("Waiting on selector...");
> 		        selector.select();
> 		    } catch (IOException e) {
> 		        // Handle error with selector
> 		    	e.printStackTrace();
> 		        break;
> 		    }
> 		}
> 		System.out.println("done...");
> 	}
> }
> Start the testcase, it will pause at "Waiting on selector..." message.  Bring down the
network connection ("ipconfig /release" I use), the following exception is thrown:
> selector open...
> Waiting on selector...
> java.net.SocketException: The connection was reset
>         at org.apache.harmony.luni.platform.OSNetworkSystem.readSocketImpl(OSNetworkSystem.java)
>         at org.apache.harmony.luni.platform.OSNetworkSystem.read(OSNetworkSystem.java:89)
>         at org.apache.harmony.nio.internal.SocketChannelImpl.readImpl(SocketChannelImpl.java:459)
>         at org.apache.harmony.nio.internal.SocketChannelImpl.read(SocketChannelImpl.java:377)
>         at org.apache.harmony.nio.internal.PipeImpl$SourceChannelImpl.read(PipeImpl.java:133)
>         at org.apache.harmony.nio.internal.SelectorImpl.processSelectResult(SelectorImpl.java:526)
>         at org.apache.harmony.nio.internal.SelectorImpl.selectInternal(SelectorImpl.java:474)
>         at org.apache.harmony.nio.internal.SelectorImpl.select(SelectorImpl.java:432)
>         at Test.main(Test.java:30)
> done...
> Again, J2SE 1.5 remains paused at "Waiting..." when the network is lost or regained.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message