-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[646] Fixed possible client hang when connecting to server.
When using secure connection (wss) while in the conditions of a bad network connection, the client connection thread can hang in JdkClientContainer's connectSynchronously() method, because it never receives neither completed() nor failed() callback. Missing failed() call added for fix. Bug: #646 Signed-off-by: Vladimir Golyakov <wolodia@narod.ru>
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../src/test/java/org/glassfish/tyrus/container/jdk/client/ConnectSynchronouslyHangTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2014, 2021 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.tyrus.container.jdk.client; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.websocket.ClientEndpoint; | ||
|
||
import org.glassfish.tyrus.client.ClientManager; | ||
import org.glassfish.tyrus.test.tools.TestContainer; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
/** | ||
* @author Vladimir Golyakov | ||
*/ | ||
public class ConnectSynchronouslyHangTest extends TestContainer { | ||
|
||
@Test | ||
public void testConnectSynchronouslyHang() throws IOException, InterruptedException { | ||
Thread clientThread = null; | ||
ServerSocket server = startBadServer(); | ||
try { | ||
clientThread = new Thread() { | ||
@Override | ||
public void run() { | ||
ClientManager client = ClientManager.createClient(JdkClientContainer.class.getName()); | ||
try { | ||
client.connectToServer(AnnotatedClientEndpoint.class, getURI("/any-endpoint", "wss")); | ||
} catch (Exception e) { | ||
// ignore | ||
} finally { | ||
client.shutdown(); | ||
} | ||
} | ||
}; | ||
clientThread.start(); | ||
|
||
// Wait for client to hang or not | ||
clientThread.join(TimeUnit.SECONDS.toMillis(5)); | ||
assertFalse("Client hangs", clientThread.isAlive()); | ||
} finally { | ||
if (clientThread != null) { | ||
clientThread.interrupt(); | ||
} | ||
server.close(); | ||
} | ||
} | ||
|
||
private ServerSocket startBadServer() throws IOException { | ||
final ServerSocket serverSocket = new ServerSocket(getPort()); | ||
new Thread() { | ||
@Override | ||
public void run() { | ||
// Server accepts client connection and disconnects for some reason | ||
try { | ||
serverSocket.setSoTimeout((int) TimeUnit.SECONDS.toMillis(5)); | ||
Socket clientSocket = serverSocket.accept(); | ||
try { | ||
Thread.sleep(200); | ||
} finally { | ||
clientSocket.close(); | ||
} | ||
} catch (Exception e) { | ||
// ignore | ||
} | ||
} | ||
}.start(); | ||
return serverSocket; | ||
} | ||
|
||
@ClientEndpoint | ||
public static class AnnotatedClientEndpoint { | ||
} | ||
} |