You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Catherine Hope (JIRA)" <ji...@apache.org> on 2010/05/28 17:31:37 UTC
[jira] Created: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
[classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
----------------------------------------------------------------------------------------------------
Key: HARMONY-6531
URL: https://issues.apache.org/jira/browse/HARMONY-6531
Project: Harmony
Issue Type: Bug
Components: Classlib
Reporter: Catherine Hope
Priority: Minor
Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
DisconnectHttpServer server = new DisconnectHttpServer();
URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
server.start();
conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
conn.getInputStream();
class DisconnectHttpServer extends Thread {
ServerSocket server = new ServerSocket();
DisconnectHttpServer() throws IOException {
server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
}
public void run() {
try {
Socket s = server.accept();
server.close();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The stack from the RI is:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Catherine Hope (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Catherine Hope updated HARMONY-6531:
------------------------------------
Attachment: 6531.patch
Fix throws a SocketException if end of stream is reached when getting a server response after requesting an input stream. The exception is cached so that subsequent calls to getInputStream (and also getContent) will wrap the original exception. This is in-line with the RI behaviour.
Regression testcase included.
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891624#action_12891624 ]
Tim Ellison commented on HARMONY-6531:
--------------------------------------
Still not working for me, with patch v2 I get
Expected SocketException
junit.framework.AssertionFailedError: Expected SocketException
at org.apache.harmony.luni.tests.java.net.URLConnectionTest.test_closedSocketBehaviour(URLConnectionTest.java:1393)
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531-2.patch, 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12878635#action_12878635 ]
Tim Ellison commented on HARMONY-6531:
--------------------------------------
I tried your patch Cath, but got the following testcase failure:
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Catherine Hope (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Catherine Hope updated HARMONY-6531:
------------------------------------
Attachment: 6531-2.patch
Apologies - the testcase passed on my computer, but since I upgraded OS's now fails and it seems to be a timing hole. I've updated the patch.
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531-2.patch, 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12878636#action_12878636 ]
Tim Ellison commented on HARMONY-6531:
--------------------------------------
Expected SocketException
junit.framework.AssertionFailedError: Expected SocketException
at org.apache.harmony.luni.tests.java.net.URLConnectionTest.test_closedSocketBehaviour(URLConnectionTest.java:1353)
at java.lang.reflect.AccessibleObject.invokeV(AccessibleObject.java:197)
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12883524#action_12883524 ]
Tim Ellison commented on HARMONY-6531:
--------------------------------------
Ping? I assume the test passes ok for you?
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-6531) [classlib][luni]
URLConnection.getInputStream() does not throw IOException when the socket
is closed
Posted by "Catherine Hope (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-6531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12892259#action_12892259 ]
Catherine Hope commented on HARMONY-6531:
-----------------------------------------
I've retested on linux and the test passes, and asked Oli to test on Windows - he gets the same result as Tim (the socket exception isn't being thrown), but the test passes on the RI on Windows.
The problem seems to be in the socket read: the Windows native recv call in the port library returns with WSAECONNABORTED ("The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable."), which is interpreted as a time-out instead of a closed socket. We've experimented with adding a case for this in the read and returning 0 and the testcase then passes, though I'm not sure if this is the right fix as it might be a timeout in other situations.
> [classlib][luni] URLConnection.getInputStream() does not throw IOException when the socket is closed
> ----------------------------------------------------------------------------------------------------
>
> Key: HARMONY-6531
> URL: https://issues.apache.org/jira/browse/HARMONY-6531
> Project: Harmony
> Issue Type: Bug
> Components: Classlib
> Reporter: Catherine Hope
> Priority: Minor
> Attachments: 6531-2.patch, 6531.patch
>
>
> Calling URLConnection.getInputStream when the socket has been closed returns an input stream that gives -1 when read from. The RI throws an IOException in this situation:
> DisconnectHttpServer server = new DisconnectHttpServer();
> URLConnection conn = (new URL("http://localhost:" + server.server.getLocalPort())).openConnection();
> server.start();
> conn.connect() // this will be successful, but the sockets will be closed immediately after the connection
> conn.getInputStream();
> class DisconnectHttpServer extends Thread {
> ServerSocket server = new ServerSocket();
> DisconnectHttpServer() throws IOException {
> server.bind(new InetSocketAddress(InetAddress.getByName("localhost"), 0));
> }
> public void run() {
> try {
> Socket s = server.accept();
> server.close();
> s.close();
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> The stack from the RI is:
> java.net.ConnectException: Connection refused
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
> at java.net.Socket.connect(Socket.java:520)
> at java.net.Socket.connect(Socket.java:470)
> at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
> at sun.net.www.http.HttpClient.openServer(HttpClient.java:523)
> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:754)
> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:626)
> at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:974)
> But I'm not sure if we should be attempting a reconnect if end of stream is reached, so I've just fixed it by throwing a SocketException that the socket has been closed.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.