Permalink
Browse files

[425044] Runtime disconnected error while running tests

All the streams are closed in case of accept fails. Otherwise, in case of accept succeeded, a client and a server are responsible to close their connections accordingly.

Signed-off-by: vrubezhny <vrubezhny@exadel.com>
  • Loading branch information...
1 parent 2eb0896 commit 661e04b600b5a6ec86a63fb2f92f74433483d738 vrubezhny committed Jan 15, 2014
@@ -108,36 +108,40 @@ public Connection accept(ListenerKey key, long attachTimeout, long handshakeTime
PipedOutputStream clientos = new PipedOutputStream();
PipedOutputStream serveros = new PipedOutputStream();
PipedInputStream clientis = new PipedInputStream();
-
- try {
- serveris.connect(clientos);
- serveros.connect(clientis);
-
- listeners.put(key, new PipedConnection(clientis, clientos));
- listeners.notifyAll();
- long startTime = System.currentTimeMillis();
- while (true) {
- try {
- listeners.wait(timeout);
- } catch (InterruptedException e) {
- throw new IOException("accept failed: interrupted"); //$NON-NLS-1$
- }
- if (!listeners.containsKey(key))
- throw new IOException("accept failed: stopped listening"); //$NON-NLS-1$
+ serveris.connect(clientos);
+ serveros.connect(clientis);
- if (listeners.get(key) != null) {
- if (System.currentTimeMillis() - startTime > timeout) {
- listeners.put(key, null);
- throw new IOException("accept failed: timed out"); //$NON-NLS-1$
- }
- continue;
+ PipedConnection clientConnection = new PipedConnection(clientis, clientos);
+ PipedConnection serverConnection = new PipedConnection(serveris, serveros);
+
+ listeners.put(key, clientConnection);
+ listeners.notifyAll();
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ try {
+ listeners.wait(timeout);
+ } catch (InterruptedException e) {
+ clientConnection.close(); // Close unused client connection (and its streams);
+ serverConnection.close(); // Close unused server connection (and its streams);
+ throw new IOException("accept failed: interrupted"); //$NON-NLS-1$
+ }
+ if (!listeners.containsKey(key)) {
+ clientConnection.close(); // Close unused client connection (and its streams);
+ serverConnection.close(); // Close unused server connection (and its streams);
+ throw new IOException("accept failed: stopped listening"); //$NON-NLS-1$
+ }
+
+ if (listeners.get(key) != null) {
+ if (System.currentTimeMillis() - startTime > timeout) {
+ listeners.put(key, null);
+ clientConnection.close(); // Close unused client connection (and its streams);
+ serverConnection.close(); // Close unused server connection (and its streams);
+ throw new IOException("accept failed: timed out"); //$NON-NLS-1$
}
- return new PipedConnection(serveris, serveros);
+ continue;
}
- }
- finally {
- serveris.close();
- serveros.close();
+ return serverConnection; // From this point both, the server and the client,
+ // are responsible to close their connections
}
}
}

0 comments on commit 661e04b

Please sign in to comment.