Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add timeout config to websocket #613

Merged
merged 4 commits into from Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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