Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,30 @@ public class CloseReason {

public static final CloseReason NORMAL = new CloseReason(WebSocketCloseStatus.NORMAL_CLOSURE.code());

public static final CloseReason ABNORMAL = new CloseReason(WebSocketCloseStatus.ABNORMAL_CLOSURE.code(), null, false);

public static final CloseReason EMPTY = new CloseReason(WebSocketCloseStatus.EMPTY.code(), null, false);

public static final CloseReason INTERNAL_SERVER_ERROR = new CloseReason(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code());

private final int code;

private final String message;

private CloseReason(int code, String message, boolean validate) {
if (validate && !WebSocketCloseStatus.isValidStatusCode(code)) {
throw new IllegalArgumentException("Invalid status code: " + code);
}
this.code = code;
this.message = message;
}

/**
*
* @param code The status code must comply with RFC-6455
*/
public CloseReason(int code) {
this(code, null);
this(code, null, true);
}

/**
Expand All @@ -35,11 +47,7 @@ public CloseReason(int code) {
* @param message
*/
public CloseReason(int code, String message) {
if (!WebSocketCloseStatus.isValidStatusCode(code)) {
throw new IllegalArgumentException("Invalid status code: " + code);
}
this.code = code;
this.message = message;
this(code, message, true);
}

public int getCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClosedException;
import io.vertx.core.http.WebSocketBase;
import io.vertx.core.http.WebSocketFrame;
import io.vertx.core.http.WebSocketFrameType;
Expand Down Expand Up @@ -342,6 +343,9 @@ private static boolean isSecurityFailure(Throwable throwable) {
}

static boolean isWebSocketIsClosedFailure(Throwable throwable, WebSocketConnectionBase connection) {
if (throwable instanceof HttpClosedException) {
return true;
}
if (!connection.isClosed()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.jboss.logging.Logger;

import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus;
import io.quarkus.vertx.utils.NoBoundChecksBuffer;
import io.quarkus.websockets.next.CloseReason;
import io.quarkus.websockets.next.Connection;
Expand Down Expand Up @@ -168,9 +169,13 @@ public CloseReason closeReason() {
WebSocketBase ws = webSocket();
if (ws.isClosed()) {
Short code = ws.closeStatusCode();
if (code == null) {
if (code == null || code == WebSocketCloseStatus.EMPTY.code()) {
// This could happen if the connection is terminated abruptly
return CloseReason.INTERNAL_SERVER_ERROR;
return CloseReason.EMPTY;
}
if (code == WebSocketCloseStatus.ABNORMAL_CLOSURE.code()) {
// This could happen if a close frame is never received
return CloseReason.ABNORMAL;
}
return new CloseReason(code, ws.closeReason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ protected WebSocketClientOptions populateClientOptions() {
clientOptions.setIdleTimeout((int) timeout.toMillis());
}
}
if (config.connectionClosingTimeout().isPresent()) {
long timeoutSeconds = config.connectionClosingTimeout().get().toSeconds();
clientOptions.setClosingTimeout(timeoutSeconds > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) timeoutSeconds);
}
Optional<TlsConfiguration> maybeTlsConfiguration = TlsConfiguration.from(tlsConfigurationRegistry,
Optional.ofNullable(tlsConfigurationName));
if (maybeTlsConfiguration.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface WebSocketsClientRuntimeConfig {

/**
* The maximum size of a frame in bytes. The default values is
* {@value io.vertx.core.http.HttpClientOptions#DEFAULT_MAX_WEBSOCKET_FRAME_SIZEX}.
* {@value io.vertx.core.http.HttpClientOptions#DEFAULT_MAX_WEBSOCKET_FRAME_SIZE}.
*/
OptionalInt maxFrameSize();

Expand All @@ -52,6 +52,15 @@ public interface WebSocketsClientRuntimeConfig {
*/
Optional<Duration> connectionIdleTimeout();

/**
* The amount of time a client will wait until it closes the TCP connection after sending a close frame.
* Any value will be {@link Duration#toSeconds() converted to seconds} and limited to {@link Integer#MAX_VALUE}.
* The default value is {@value io.vertx.core.http.HttpClientOptions#DEFAULT_WEBSOCKET_CLOSING_TIMEOUT}s
*
* @see io.vertx.core.http.WebSocketClientOptions#setClosingTimeout(int)
*/
Optional<Duration> connectionClosingTimeout();

/**
* The strategy used when an error occurs but no error handler can handle the failure.
* <p>
Expand Down
Loading