-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This includes a change to the multiplexed websocket format to indicate to the client that the websocket itself will soon stop, so no more streams should be started on it, and existing calls should be finished. This reflects the same basic semantics that http2 uses for GO_AWAY. An earlier change to how the HealthCheck service is stopped is reverted here, by ensuring that gRPC doesn't reuse an existing executor, so that it remains running throughout shutdown. Autocomplete streams are correctly ended by the server during the shutdown process. Fixes #2985
- Loading branch information
Showing
16 changed files
with
379 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
server/jetty/src/main/java/io/deephaven/server/jetty/WebsocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.deephaven.server.jetty; | ||
|
||
import io.grpc.servlet.web.websocket.GrpcWebsocket; | ||
import io.grpc.servlet.web.websocket.MultiplexedWebSocketServerStream; | ||
import jakarta.websocket.Endpoint; | ||
import org.eclipse.jetty.util.component.Graceful; | ||
import org.eclipse.jetty.websocket.jakarta.server.internal.JakartaWebSocketServerContainer; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Supplier; | ||
|
||
import static io.grpc.servlet.web.websocket.MultiplexedWebSocketServerStream.GRACEFUL_CLOSE; | ||
|
||
/** | ||
* Helper class to bridge the gap between Jetty's Graceful interface and the jakarta implementation of the supported | ||
* grpc websocket transports. | ||
* <p> | ||
* </p> | ||
* This type is not an Endpoint, so only one instance of this can create and shutdown many endpoints. | ||
*/ | ||
public class WebsocketFactory implements Graceful { | ||
private final AtomicReference<CompletableFuture<Void>> shutdown = new AtomicReference<>(); | ||
|
||
private final Supplier<GrpcWebsocket> factory; | ||
private final JakartaWebSocketServerContainer jettyWebsocketContainer; | ||
|
||
public WebsocketFactory(Supplier<GrpcWebsocket> factory, JakartaWebSocketServerContainer jettyWebsocketContainer) { | ||
this.factory = factory; | ||
this.jettyWebsocketContainer = jettyWebsocketContainer; | ||
} | ||
|
||
public Endpoint create() { | ||
return factory.get(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> shutdown() { | ||
// Modeled after AbstractHTTP2ServerConnectionFactory.HTTP2SessionContainer.shutdown() | ||
CompletableFuture<Void> result = new CompletableFuture<>(); | ||
// Simply by setting the shutdown, we don't allow new endpoint instances to be created | ||
if (shutdown.compareAndSet(null, result)) { | ||
// iterate created transports, and if we can, prevent new streams | ||
CompletableFuture.allOf( | ||
jettyWebsocketContainer.getOpenSessions().stream() | ||
.map(s -> (MultiplexedWebSocketServerStream.GracefulClose) s.getUserProperties() | ||
.get(GRACEFUL_CLOSE)) | ||
.map(MultiplexedWebSocketServerStream.GracefulClose::get) | ||
.filter(Objects::nonNull) | ||
.toArray(CompletableFuture[]::new)) | ||
.whenComplete((success, throwable) -> { | ||
if (throwable == null) { | ||
// When all clients have acknowledged, complete | ||
result.complete(success); | ||
} else { | ||
result.completeExceptionally(throwable); | ||
} | ||
}); | ||
return result; | ||
} else { | ||
return shutdown.get(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isShutdown() { | ||
return shutdown.get() != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.