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

Attempt for max timeout #2303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -1,10 +1,8 @@
package io.vertx.ext.web.handler.sockjs;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;

import java.util.Base64;

/**
Expand All @@ -22,22 +20,27 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
switch (member.getKey()) {
case "maxAddressLength":
if (member.getValue() instanceof Number) {
obj.setMaxAddressLength(((Number)member.getValue()).intValue());
obj.setMaxAddressLength(((Number) member.getValue()).intValue());
}
break;
case "maxHandlersPerSocket":
if (member.getValue() instanceof Number) {
obj.setMaxHandlersPerSocket(((Number)member.getValue()).intValue());
obj.setMaxHandlersPerSocket(((Number) member.getValue()).intValue());
}
break;
case "pingTimeout":
if (member.getValue() instanceof Number) {
obj.setPingTimeout(((Number)member.getValue()).longValue());
obj.setPingTimeout(((Number) member.getValue()).longValue());
}
break;
case "replyTimeout":
if (member.getValue() instanceof Number) {
obj.setReplyTimeout(((Number)member.getValue()).longValue());
obj.setReplyTimeout(((Number) member.getValue()).longValue());
}
break;
case "eventbutTimeout":
if (member.getValue() instanceof Number) {
obj.setEventBusTimeout(((Number) member.getValue()).longValue());
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public class SockJSBridgeOptions extends BridgeOptions {
*/
public static final long DEFAULT_REPLY_TIMEOUT = 30 * 1000;

/**
* Default value for Socket timeout = 50000 ms
*/
public static final long DEFAULT_EVENT_BUS_TIMEOUT = 50 * 1000;


private long eventBusTimeout;
private int maxAddressLength;
private int maxHandlersPerSocket;
private long pingTimeout;
Expand All @@ -67,6 +74,7 @@ public SockJSBridgeOptions(SockJSBridgeOptions other) {
this.maxHandlersPerSocket = other.maxHandlersPerSocket;
this.pingTimeout = other.pingTimeout;
this.replyTimeout = other.replyTimeout;
this.eventBusTimeout = other.eventBusTimeout;
}

/**
Expand All @@ -78,6 +86,7 @@ public SockJSBridgeOptions() {
this.maxHandlersPerSocket = DEFAULT_MAX_HANDLERS_PER_SOCKET;
this.pingTimeout = DEFAULT_PING_TIMEOUT;
this.replyTimeout = DEFAULT_REPLY_TIMEOUT;
this.eventBusTimeout = DEFAULT_EVENT_BUS_TIMEOUT;
}

/**
Expand Down Expand Up @@ -139,6 +148,19 @@ public SockJSBridgeOptions setReplyTimeout(long replyTimeout) {
return this;
}

public SockJSBridgeOptions setEventBusTimeout(long eventBusTimeout) {
if (eventBusTimeout < 1) {
throw new IllegalArgumentException("Eventbus must be > 0");
}
this.eventBusTimeout = eventBusTimeout;
return this;
}

public long getEventBusTimeout(){
return this.eventBusTimeout;
}


@Override
public SockJSBridgeOptions addInboundPermitted(PermittedOptions permitted) {
super.addInboundPermitted(permitted);
Expand All @@ -163,6 +185,7 @@ public SockJSBridgeOptions setOutboundPermitteds(List<PermittedOptions> outbound
return this;
}


@Override
public JsonObject toJson() {
JsonObject json = new JsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class EventBusBridgeImpl implements Handler<SockJSSocket> {
private final int maxHandlersPerSocket;
private final long pingTimeout;
private final long replyTimeout;
private final long maxTimeout;
private final Vertx vertx;
private final EventBus eb;
private final Map<String, Message<?>> messagesAwaitingReply = new HashMap<>();
Expand All @@ -90,6 +91,7 @@ public EventBusBridgeImpl(Vertx vertx, AuthorizationProvider authzProvider, Sock
this.maxHandlersPerSocket = options.getMaxHandlersPerSocket();
this.pingTimeout = options.getPingTimeout();
this.replyTimeout = options.getReplyTimeout();
this.maxTimeout = options.getEventBusTimeout();
this.bridgeEventHandler = bridgeEventHandler;
}

Expand Down Expand Up @@ -326,7 +328,7 @@ public void handle(final SockJSSocket sock) {
// Start a checker to check for pings
PingInfo pingInfo = new PingInfo();
pingInfo.timerID = vertx.setPeriodic(pingTimeout, id -> {
if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout) {
if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout && System.currentTimeMillis() - pingInfo.socketCreationTs >= maxTimeout) {
// Trigger an event to allow custom behavior before disconnecting client.
checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_IDLE, null, sock),
// We didn't receive a ping in time so close the socket
Expand Down Expand Up @@ -662,6 +664,7 @@ private static class Match {
private static final class PingInfo {
long lastPing;
long timerID;
long socketCreationTs = System.currentTimeMillis();
}

private static final class SockInfo {
Expand Down