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

EngineIO Client could not keep connection alive when using SSL #16

Closed
matrixcloud opened this issue Apr 17, 2019 · 7 comments
Closed

EngineIO Client could not keep connection alive when using SSL #16

matrixcloud opened this issue Apr 17, 2019 · 7 comments

Comments

@matrixcloud
Copy link

Hi,

I tried to connect an SSL engine-io server but got failed.

Server Code

The following is my server code, I deploy the servlet in a Jetty Container which is using SSL.

public class SockServlet extends HttpServlet {
    private final EngineIoServer mEngineIoServer = new EngineIoServer();
    private static final Logger logger = Logger.getLogger(ConnectionListener.class.getName());

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        logger.info("Sock Servlet Initialized");

        initIO();
    }

    private void initIO() {
        mEngineIoServer.on("connection", new Emitter.Listener() {
            @Override
            public void call(Object... args) {
                EngineIoSocket socket = (EngineIoSocket) args[0];
                logger.info("A client connected: " + socket.getId());
                socket.send(new Packet<>(Packet.MESSAGE, "Hi client, I am here"));

                socket.on("message", new Emitter.Listener() {
                    @Override
                    public void call(Object... objects) {
                        String message = (String) objects[0];
                        logger.info("received: " + message);
                        logger.info("received");
                    }
                });
            }
        });
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        mEngineIoServer.handleRequest(req, resp);
    }

    public EngineIoServer getmEngineIoServer() {
         return mEngineIoServer;
    }
}

maven dependency

<dependency>
        <groupId>io.socket</groupId>
        <artifactId>engine.io-server</artifactId>
        <version>1.3.1</version>
</dependency>

Client Code

I created an engine-io client using engine.io-client.

const io = require('engine.io-client');

const opts = {
  path: '/rest-api/sock',
  rejectUnauthorized: false,
};

const socket = io('https://localhost:8443', opts);
socket.on('open', () => {
  console.log('connected');
})
socket.on('message', (data) => {
  console.log('received: ', data);
});

socket.on('error', (err) => {
  console.log('error', err);
})

console.log('client started');

dependency

 "engine.io-client": "^3.2.1",

Errors

When I executed the client code using node client.js, it showed the first connection has been established, but the connection couldn't keep alive.

client started
connected
received:  Hi client, I am here
error { Error: xhr poll error
    at XHR.Transport.onError (C:\Projects\history-notification-client\node_modules\engine.io-client\lib\transport.js:67:13)
    at Request.<anonymous> (C:\Projects\history-notification-client\node_modules\engine.io-client\lib\transports\polling-xhr.js:130:10)
    at Request.Emitter.emit (C:\Projects\history-notification-client\node_modules\component-emitter\index.js:133:20)
    at Request.onError (C:\Projects\history-notification-client\node_modules\engine.io-client\lib\transports\polling-xhr.js:311:8)
    at Timeout._onTimeout (C:\Projects\history-notification-client\node_modules\engine.io-client\lib\transports\polling-xhr.js:258:18)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5) type: 'TransportError', description: 503 }
@matrixcloud
Copy link
Author

My further investigation below.

engine.io-client:polling-xhr xhr open POST: https://localhost:8443/rest-api/sock/?EIO=3&transport=polling&t=MegRN4b&b64=1&sid=MegEN9J +9ms
  engine.io-client:polling-xhr xhr data 1:1 +0ms
  engine.io-client:polling-xhr xhr1 XMLHttpRequest {
  UNSENT: 0,
  OPENED: 1,
  HEADERS_RECEIVED: 2,
  LOADING: 3,
  DONE: 4,
  readyState: 4,
  onreadystatechange: [Function],
  responseText: 'Error: read ECONNRESET\n    at TLSWrap.onread (net.js:622:25)',
  responseXML: '',
  status: 503,
  statusText: { Error: read ECONNRESET
    at TLSWrap.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' },
  open: [Function],
  setDisableHeaderCheck: [Function],
  setRequestHeader: [Function],
  getResponseHeader: [Function],
  getAllResponseHeaders: [Function],
  getRequestHeader: [Function],
  send: [Function],
  handleError: [Function],
  abort: [Function],
  addEventListener: [Function],
  removeEventListener: [Function],
  dispatchEvent: [Function] } +16ms

node -v shows v8.14.0

@trinopoty
Copy link
Collaborator

The status code 503 is 503 Service Unavailable. Are you sure your Jetty server is properly configured?

@trinopoty
Copy link
Collaborator

trinopoty commented Apr 17, 2019

Also, I don't know what browser you're using but https to localhost seems troublesome and could be the thing causing the issue.

EDIT: Please make sure you're using a certificate that your browser trusts. This could be the issue causing the ECONNRESET.

@matrixcloud
Copy link
Author

@trinopoty I can ensure the server is available, and from the logs, you can see that the first connection has been established because the client received a message from server received: Hi client, I am here.

I used the engine-client in node. I will try to config the ssl options.

Thanks for your quick reply!

@matrixcloud
Copy link
Author

It seems the error caused by the server since I tried a simple demo and it connected successfully.

@trinopoty
Copy link
Collaborator

I see. Thanks for the update.

@matrixcloud
Copy link
Author

I have found the root cause, it's caused by org.eclipse.jetty.servlets.DoSFilter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants