首页 > 解决方案 > Wildfly 挂起导致 undertow websocket 连接失败

问题描述

我有一个简单的@Startup 服务,其中包含一系列 websocket 连接创建的 @PostConstruct 方法:

    public void connect(String uri, int timeOut) throws Exception {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        ClientEndpointConfig config = Builder.create().build();
        config.getUserProperties().put("io.undertow.websocket.CONNECT_TIMEOUT", timeOut);
        container.connectToServer(this.endpoint, config, new URI(uri));
    }

在某些时候,connectToServer 调用因ClosedChannelException. 就代码逻辑而言,原因非常简单,但我不知道如何解决它: Wildfly 挂起导致ServerWebSocketContainer::pause被调用

    public synchronized void pause(PauseListener listener) {
        closed = true;
        ...

并且以ServerWebSocketContainer::connectToServer我能想象的最糟糕的方式处理这种行为:)

    public Session connectToServer(final Endpoint endpointInstance, final ClientEndpointConfig config, final URI path) throws DeploymentException, IOException {
        if(closed) {
            throw new ClosedChannelException();
        }
        ...
  1. 如何等待undertow满载?
  2. 如何在 ServletContextListener 中注入 @Ejb 类来移动 contextInitialized 中的任务?
  3. 或者也许利用球衣ApplicationEventListener?

在延迟 10-15 秒的新线程中执行没有意义 - 可能ContainerProvider.getWebSocketContainer()会导致加载扩展加载,然后是UndertowDeploymentInfoService::suspend

标签: wildflyundertowsuspend

解决方案


推荐阅读