mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 18:18:02 -05:00
fix: release origin connections after refused WebSocket upgrades (#7694)
This commit is contained in:
1 parent
8cff513c8d
commit
8b81638490
6 files changed
+193
-2
No files matched your search
@@ -1,9 +1,13 @@
|
||||
package io.floci.aws.core.common;
|
||||
|
||||
import io.vertx.core.http.HttpClientRequest;
|
||||
import io.vertx.core.http.HttpClosedException;
|
||||
import io.vertx.core.http.HttpConnection;
|
||||
import io.vertx.core.http.HttpMethod;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import io.vertx.core.http.HttpVersion;
|
||||
import io.vertx.core.net.NetSocket;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* The parts of proxying a WebSocket handshake that the proxies Floci emulates share. An ALB and a
|
||||
@@ -13,6 +17,8 @@ import io.vertx.core.net.NetSocket;
|
||||
*/
|
||||
public final class WebSocketUpgrades {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(WebSocketUpgrades.class);
|
||||
|
||||
private WebSocketUpgrades() {
|
||||
}
|
||||
|
||||
@@ -34,6 +40,25 @@ public final class WebSocketUpgrades {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a refused connect() request once forwarding has finished or failed. Reading its
|
||||
* response does not finish the request, so the connection still holds a pool slot. Only the
|
||||
* expected closed-connection notification from this deliberate cleanup is logged at debug.
|
||||
*/
|
||||
public static void closeRefusedRequest(HttpClientRequest request) {
|
||||
HttpConnection connection = request.connection();
|
||||
request.exceptionHandler(err -> {
|
||||
if (err instanceof HttpClosedException) {
|
||||
LOG.debugv("Refused WebSocket origin connection closed: {0}", connection.remoteAddress());
|
||||
} else {
|
||||
LOG.warnv(err, "Unexpected error closing refused WebSocket origin connection to {0}",
|
||||
connection.remoteAddress());
|
||||
}
|
||||
});
|
||||
connection.close().onFailure(err ->
|
||||
LOG.warnv(err, "Could not close refused WebSocket origin connection to {0}", connection.remoteAddress()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies everything {@code source} reads to {@code destination}, pausing the source while the
|
||||
* destination's write queue is full. {@code onData} runs for each buffer, and {@code close} when
|
||||
|
||||
@@ -225,11 +225,13 @@ public class CloudFrontWebSocketProxy {
|
||||
});
|
||||
response.endHandler(ignored -> {
|
||||
clock.stop();
|
||||
WebSocketUpgrades.closeRefusedRequest(originRequest);
|
||||
viewerResponse.end();
|
||||
});
|
||||
response.exceptionHandler(err -> {
|
||||
clock.stop();
|
||||
LOG.debugv("CloudFront origin failed while refusing a WebSocket upgrade: {0}", err.getMessage());
|
||||
originRequest.reset();
|
||||
LOG.warnv(err, "CloudFront origin failed while refusing a WebSocket upgrade");
|
||||
viewerResponse.reset();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1598,7 +1598,15 @@ public class ElbV2DataPlane {
|
||||
if (resp.getHeader("Content-Length") == null) {
|
||||
req.response().setChunked(true);
|
||||
}
|
||||
resp.pipeTo(req.response());
|
||||
resp.pipeTo(req.response())
|
||||
.onComplete(result -> {
|
||||
if (result.failed()) {
|
||||
LOG.warnv(result.cause(),
|
||||
"Failed relaying refused WebSocket upgrade from {0}:{1}",
|
||||
host, port);
|
||||
}
|
||||
WebSocketUpgrades.closeRefusedRequest(clientReq);
|
||||
});
|
||||
return;
|
||||
}
|
||||
req.response().putHeader("Connection", "Upgrade");
|
||||
|
||||
Reference in new issue
Block a user