Skip to content

Commit

Permalink
feat: add timeout config to websocket (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Jul 28, 2022
1 parent 55b99ad commit 76a42fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -70,7 +70,10 @@ public WebsocketConnection(Consumer<WebsocketConnectionConfig> configSpec) {
config = WebsocketConnectionConfig.process(configSpec);

// webSocketFactory and proxy configuration
this.webSocketFactory = new WebSocketFactory();
this.webSocketFactory = new WebSocketFactory()
.setConnectionTimeout(config.connectionTimeout())
.setSocketTimeout(config.socketTimeout());

if (config.proxyConfig() != null) {
webSocketFactory.getProxySettings()
.setHost(config.proxyConfig().getHostname())
Expand Down
Expand Up @@ -36,6 +36,12 @@ public void validate() {
if (wsPingPeriod < 0) {
throw new RuntimeException("wsPingPeriod must be 0 or greater, set to 0 to disable!");
}
if (connectionTimeout < 0) {
throw new RuntimeException("connectionTimeout must be 0 or greater, set to 0 to disable!");
}
if (socketTimeout < 0) {
throw new RuntimeException("socketTimeout must be 0 or greater, set to 0 to disable!");
}
Objects.requireNonNull(taskExecutor, "taskExecutor may not be null!");
Objects.requireNonNull(backoffStrategy, "backoffStrategy may not be null!");
Objects.requireNonNull(onStateChanged, "onStateChanged may not be null!");
Expand All @@ -59,6 +65,16 @@ public void validate() {
*/
private int wsPingPeriod = 0;

/**
* Websocket timeout milliseconds for establishing a connection (0 = disabled).
*/
private int connectionTimeout = 60_000;

/**
* Websocket timeout milliseconds for read and write operations (0 = disabled).
*/
private int socketTimeout = 10_000;

/**
* WebSocket Headers
*/
Expand Down

0 comments on commit 76a42fa

Please sign in to comment.