Гуакамоле: несколько одновременных подключений vnc через websocket закрывают друг друга - PullRequest
0 голосов
/ 26 января 2019

Мы используем гуакамоле для доступа к удаленному рабочему столу в веб-браузере.Мы пытаемся использовать websocket-tunnel для повышения производительности, но если я открою две вкладки в своем браузере, подключаясь к двум различным vnc-серверам через один и тот же сервер guacd, одна страница зависнет (websocket прекратит отправлять / получать любые сообщения), другая получит ошибку, например: 776 и отключен.Но если мы используем http сервлет, то это решается.Кто-нибудь сталкивался с подобной проблемой?Вот мои настройки.

  1. guacamole-js использовался в веб-браузере.
  2. Мы используем x11vnc, guacd, установленный с тем же linux box
  3. Мы разработалидве конечные точки используют spring-boot: websocket-tunnel, расширяя GuacamoleWebSocketTunnelEndpoint,

    @Component
    public class MyGuacamoleWebSocketEndPoint extends GuacamoleWebSocketTunnelEndpoint {@Autowired
    MyGuacamoleAutoProperties myGuacamoleAutoProperties;
    
    private static final Logger logger = LoggerFactory.getLogger(MyGuacamoleWebSocketEndPoint.class);
    
    public myGuacamoleWebSocketEndPoint() {
        logger.info("MyGuacamoleWebSocketEndPoint constructed!");
    }
    
    @Override
    protected GuacamoleTunnel createTunnel(Session session, EndpointConfig endpointConfig) throws GuacamoleException{
    
        Map<String, List<String>> parameterMap = session.getRequestParameterMap();
    
        String vid = getFirstValue(parameterMap,myGuacamoleAutoProperties.getVncPortParaName());
        String host = getFirstValue(parameterMap,myGuacamoleAutoProperties.getVncHostParaName());
    
        // Get client information
        GuacamoleClientInformation info = new GuacamoleClientInformation();
        // Create our configuration
        GuacamoleConfiguration config  = new GuacamoleConfiguration();
        config.setProtocol("vnc");
        config.setParameter("hostname", host);
        config.setParameter("port", vid);
        config.setParameter("password", myGuacamoleAutoProperties.getVncPassword());
    
        String guacdHost=host;
        // Connect to guacd
        GuacamoleTunnel tunnel;
        if(myGuacamoleAutoProperties.isUseStandaloneGuacd()){
            guacdHost=myGuacamoleAutoProperties.getGuacdHost();
        }
        GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
                new InetGuacamoleSocket(guacdHost,myGuacamoleAutoProperties.getGuacdPort()), config);
        tunnel=new SimpleGuacamoleTunnel(socket);
        GuacamoleTunnel monitoredTunnel = new DelemyingGuacamoleTunnel(tunnel) {
    
            @Override
            public GuacamoleReader acquireReader() {
                logger.debug("Open tunnel on port: '" + getPort() + "', uuid: '" + getUUID() + "' and connection_id: '" + ((ConfiguredGuacamoleSocket)getSocket()).getConnectionID() + "'.");
                return super.acquireReader();
            }
    
            @Override
            public void close() throws GuacamoleException {
                logger.debug("Close tunnel on port: '" + getPort() + "', uuid: '" + getUUID() + "' and connection_id: '" + ((ConfiguredGuacamoleSocket)getSocket()).getConnectionID() + "'.");
                super.close();
            }
    
            /**
             * Get the Guac Port from the Tunnel->Socket->Configuration.
             *
             * @return Guac Port
             */
            private String getPort() {
                return ((ConfiguredGuacamoleSocket) getSocket()).getConfiguration().getParameter("port");
            }
        };
    
        return monitoredTunnel;
    }
    
    private String getFirstValue(Map<String, List<String>> map, String key) {
        List<String> values = map.get(key);
        return values != null ? values.get(0) : null;
    }
    

http-туннель-сервлет, расширяя GuacamoleHTTPTunnelServlet

@Component
public class MyGuacamoleTunnelServlet extends GuacamoleHTTPTunnelServlet {

    @Autowired
    MyGuacamoleAutoProperties myGuacamoleAutoProperties;

    @Override
    protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
        String vid = request.getParameter(myGuacamoleAutoProperties.getVncPortParaName());
        String host = request.getParameter(myGuacamoleAutoProperties.getVncHostParaName());

        // Create our configuration
        GuacamoleConfiguration config = new GuacamoleConfiguration();
        config.setProtocol("vnc");
        config.setParameter("hostname", host);
        config.setParameter("port", vid);
        //config.setParameter("user",  request.getParameter("user"));
        config.setParameter("password", myGuacamoleAutoProperties.getVncPassword());

        // Connect to guacd
        String guacdHost=host;
        GuacamoleTunnel tunnel;
        if(myGuacamoleAutoProperties.isUseStandaloneGuacd()){
            guacdHost=myGuacamoleAutoProperties.getGuacdHost();
        }

        GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
                new InetGuacamoleSocket(guacdHost,myGuacamoleAutoProperties.getGuacdPort()), config);
        tunnel=new SimpleGuacamoleTunnel(socket);
        // Return a new tunnel which uses the connected socket
        return tunnel;
    }
}

Журналы Guacd здесь:

Jan 25 04:32:58 vnchost guacd[105232]: Protocol "vnc" selected
Jan 25 04:32:58 vnchost guacd[105232]: Connection ID is "$7d545e7e-0a29-40e5-a4a3-9964fa07b22b"
Jan 25 04:32:58 vnchost guacd[105232]: VNC server supports protocol version 3.8 (viewer 3.8)
Jan 25 04:32:58 vnchost guacd[105232]: We have 1 security types to read
Jan 25 04:32:58 vnchost guacd[105232]: 0) Received security type 1
Jan 25 04:32:58 vnchost guacd[105232]: Selecting security type 1 (0/1 in the list)
Jan 25 04:32:58 vnchost guacd[105232]: Selected Security Scheme 1
Jan 25 04:32:58 vnchost guacd[105232]: No authentication needed
Jan 25 04:32:58 vnchost guacd[105232]: VNC authentication succeeded
Jan 25 04:32:58 vnchost guacd[105232]: Desktop name "vnchost:0"
Jan 25 04:32:58 vnchost guacd[105232]: Connected to VNC server, using protocol version 3.8
Jan 25 04:32:58 vnchost guacd[105232]: VNC server default format:
Jan 25 04:32:58 vnchost guacd[105232]:  32 bits per pixel.
Jan 25 04:32:58 vnchost guacd[105232]:  Least significant byte first in each pixel.
Jan 25 04:32:58 vnchost guacd[105232]:  TRUE colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Jan 25 04:32:58 vnchost guacd[105232]: Starting client
Jan 25 04:32:58 vnchost guacd[105232]: client2server supported messages (bit flags)
Jan 25 04:32:58 vnchost guacd[105232]: 00: 00ff 0081 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 08: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 10: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 18: 0000 0000 0000 0000 - 0000 0000 0000 0004
Jan 25 04:32:58 vnchost guacd[105232]: server2client supported messages (bit flags)
Jan 25 04:32:58 vnchost guacd[105232]: 00: 001f 0080 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 08: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 10: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:32:58 vnchost guacd[105232]: 18: 0000 0000 0000 0000 - 0000 0000 0000 0004
Jan 25 04:32:58 vnchost guacd[105232]: Connected to Server "unknown (LibVNCServer 0.9.9)”

Jan 25 04:36:28 vnchost guacd[105538]: Protocol "vnc" selected
Jan 25 04:36:28 vnchost guacd[105538]: Connection ID is "$6fd98484-1dd0-4c66-aa04-6c358cd30548"
Jan 25 04:36:29 vnchost guacd[105538]: VNC server supports protocol version 3.8 (viewer 3.8)
Jan 25 04:36:29 vnchost guacd[105538]: We have 1 security types to read
Jan 25 04:36:29 vnchost guacd[105538]: 0) Received security type 1
Jan 25 04:36:29 vnchost guacd[105538]: Selecting security type 1 (0/1 in the list)
Jan 25 04:36:29 vnchost guacd[105538]: Selected Security Scheme 1
Jan 25 04:36:29 vnchost guacd[105538]: No authentication needed
Jan 25 04:36:29 vnchost guacd[105538]: VNC authentication succeeded
Jan 25 04:36:29 vnchost guacd[105538]: Desktop name "vnchost:2"
Jan 25 04:36:29 vnchost guacd[105538]: Connected to VNC server, using protocol version 3.8
Jan 25 04:36:29 vnchost guacd[105538]: VNC server default format:
Jan 25 04:36:29 vnchost guacd[105538]:  32 bits per pixel.
Jan 25 04:36:29 vnchost guacd[105538]:  Least significant byte first in each pixel.
Jan 25 04:36:29 vnchost guacd[105538]:  TRUE colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Jan 25 04:36:29 vnchost guacd[105538]: Starting client
Jan 25 04:36:29 vnchost guacd[105538]: client2server supported messages (bit flags)
Jan 25 04:36:29 vnchost guacd[105538]: 00: 00ff 0081 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 08: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 10: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 18: 0000 0000 0000 0000 - 0000 0000 0000 0004
Jan 25 04:36:29 vnchost guacd[105538]: server2client supported messages (bit flags)
Jan 25 04:36:29 vnchost guacd[105538]: 00: 001f 0080 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 08: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 10: 0000 0000 0000 0000 - 0000 0000 0000 0000
Jan 25 04:36:29 vnchost guacd[105538]: 18: 0000 0000 0000 0000 - 0000 0000 0000 0004
Jan 25 04:36:29 vnchost guacd[105538]: Connected to Server "unknown (LibVNCServer 0.9.9)"
Jan 25 04:36:29 vnchost guacd[105538]: Connection aborted
Jan 25 04:36:30 vnchost guacd[105538]: Client disconnected
Jan 25 04:36:30 vnchost kernel: guacd[105538]: segfault at 1000003f8 ip 00007fbfce7bdc24 sp 00007ffe0d31c990 error 4 in libguac-client-vnc.so.0.0.0[7fbfce7b2000+f000]
Jan 25 04:36:30 vnchost abrt-hook-ccpp: Process 105538 (guacd) of user 0 killed by SIGSEGV - dumping core
Jan 25 04:36:30 vnchost abrt-server: Executable '/usr/local/sbin/guacd' doesn't belong to any package and ProcessUnpackaged is set to 'no'
Jan 25 04:36:43 vnchost guacd[105232]: Client is not responding.
Jan 25 04:36:43 vnchost guacd[105232]: Client disconnected
Jan 25 04:36:43 vnchost kernel: guacd[105232]: segfault at 1000003f8 ip 00007fbfce7bdc24 sp 00007ffe0d31c990 error 4 in libguac-client-vnc.so.0.0.0[7fbfce7b2000+f000]
Jan 25 04:36:43 vnchost abrt-hook-ccpp: Process 105232 (guacd) of user 0 killed by SIGSEGV - ignoring (repeated crash)

Журнал приложения здесь:

2019-01-25 12:32:58.441 DEBUG 1 --- [nio-8080-exec-6] o.a.guacamole.net.InetGuacamoleSocket    : Connecting to guacd at vnchost:4832.
2019-01-25 12:32:58.961 DEBUG 1 --- [       Thread-6] .g.b.g.w.e.MyGuacamoleWebSocketEndPoint : Open tunnel on port: '5900', uuid: '2eba77c8-2f74-42a3-8ca5-4cf882ee3653' and connection_id: '$7d545e7e-0a29-40e5-a4a3-9964fa07b22b'.

2019-01-25 12:36:28.785 DEBUG 1 --- [nio-8080-exec-2] o.a.guacamole.net.InetGuacamoleSocket    : Connecting to guacd at vnchost:4832.
2019-01-25 12:36:29.137 DEBUG 1 --- [       Thread-8] .g.b.g.w.e.MyGuacamoleWebSocketEndPoint : Open tunnel on port: '5902', uuid: '67446967-2e8e-42d7-9c73-68c2a80a270b' and connection_id: '$6fd98484-1dd0-4c66-aa04-6c358cd30548'.
2019-01-25 12:36:30.510 DEBUG 1 --- [       Thread-8] o.a.g.w.GuacamoleWebSocketTunnelEndpoint : Connection to guacd closed.

org.apache.guacamole.GuacamoleConnectionClosedException: Connection to guacd is closed.
        at org.apache.guacamole.io.ReaderGuacamoleReader.read(ReaderGuacamoleReader.java:183) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint$2.run(GuacamoleWebSocketTunnelEndpoint.java:160) ~[guacamole-common-0.9.14.jar!/:na]
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:210) ~[na:1.8.0_191]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_191]
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[na:1.8.0_191]
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[na:1.8.0_191]
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_191]
        at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_191]
        at org.apache.guacamole.io.ReaderGuacamoleReader.read(ReaderGuacamoleReader.java:169) ~[guacamole-common-0.9.14.jar!/:na]
        ... 1 common frames omitted
 2019-01-25 12:36:30.511 DEBUG 1 --- [       Thread-8] .g.b.g.w.e.MyGuacamoleWebSocketEndPoint : Close tunnel on port: '5902', uuid: '67446967-2e8e-42d7-9c73-68c2a80a270b' and connection_id: '$6fd98484-1dd0-4c66-aa04-6c358cd30548'.
2019-01-25 12:36:30.511 DEBUG 1 --- [       Thread-8] o.a.guacamole.net.InetGuacamoleSocket    : Closing socket to guacd.
2019-01-25 12:36:30.627 DEBUG 1 --- [nio-8080-exec-4] o.a.g.w.GuacamoleWebSocketTunnelEndpoint : Connection to guacd closed.

org.apache.guacamole.GuacamoleConnectionClosedException: Connection to guacd is closed.
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:64) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:73) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint.onMessage(GuacamoleWebSocketTunnelEndpoint.java:221) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint$1.onMessage(GuacamoleWebSocketTunnelEndpoint.java:129) [guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint$1.onMessage(GuacamoleWebSocketTunnelEndpoint.java:125) [guacamole-common-0.9.14.jar!/:na]
        at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:394) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
Caused by: java.net.SocketException: Socket closed
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118) ~[na:1.8.0_191]
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141) ~[na:1.8.0_191]
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) ~[na:1.8.0_191]
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:58) ~[guacamole-common-0.9.14.jar!/:na]
        ... 22 common frames omitted

2019-01-25 12:36:33.068 DEBUG 1 --- [nio-8080-exec-7] o.a.g.w.GuacamoleWebSocketTunnelEndpoint : Connection to guacd closed.

org.apache.guacamole.GuacamoleConnectionClosedException: Connection to guacd is closed.
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:64) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:73) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint.onMessage(GuacamoleWebSocketTunnelEndpoint.java:221) ~[guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint$1.onMessage(GuacamoleWebSocketTunnelEndpoint.java:129) [guacamole-common-0.9.14.jar!/:na]
        at org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint$1.onMessage(GuacamoleWebSocketTunnelEndpoint.java:125) [guacamole-common-0.9.14.jar!/:na]
        at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:394) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) [tomcat-embed-websocket-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.31.jar!/:8.5.31]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
Caused by: java.net.SocketException: Socket closed
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118) ~[na:1.8.0_191]
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295) ~[na:1.8.0_191]
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141) ~[na:1.8.0_191]
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) ~[na:1.8.0_191]
        at org.apache.guacamole.io.WriterGuacamoleWriter.write(WriterGuacamoleWriter.java:58) ~[guacamole-common-0.9.14.jar!/:na]
        ... 22 common frames omitted

1 Ответ

0 голосов
/ 28 января 2019

Я думаю, что нашел основную причину здесь. В моей предыдущей реализации веб-сокета я настроил контейнер Spring для использования одного и того же экземпляра для обработки другого сеанса веб-сокета, который, в свою очередь, будет обрабатывать другое соединение vnc. Кажется, это заставило guacd отключить все сокеты от веб-сервера гуакамоле. Путем изменения инициализировать новый экземпляр EndPoint для каждого сеанса Websocket, это разрешится.

Основная причина лежит в GuacamoleWebSocketTunnelEndpoint, расширенном MyGuacamoleWebSocketEndPoint. GuacamoleWebSocketTunnelEndpoint использует tunnel для хранения текущего соединения с процессом guacd, если мы инициируем MyGuacamoleWebSocketEndPoint как one Bean в Spring и используем его для обработки всех сессий веб-сокетов, приходящих на него, тогда это вызовет непредсказуемый поведение, как упомянуто выше.

@Override
@OnOpen
public void onOpen(final Session session, EndpointConfig config) {

    // Store underlying remote for future use via sendInstruction()
    remote = session.getBasicRemote();

    try {

        // Get tunnel
        **tunnel = createTunnel(session, config);**
        if (tunnel == null) {
            closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND);
            return;
        }

    }
    catch (GuacamoleException e) {
        logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage());
        logger.debug("Error connecting WebSocket tunnel.", e);
        closeConnection(session, e.getStatus().getGuacamoleStatusCode(),
                e.getWebSocketCode());
        return;
    }
...}

На самом деле это типичная проблема совместного использования экземпляров между разными потоками.

В документе гуакамоле приведен только пример для реализации приложения на основе HttpServlet. С приложением, основанным на websocket, мы сами по себе.

...