IXWebSocket icon indicating copy to clipboard operation
IXWebSocket copied to clipboard

Unable to connect to gateway.webpubsub.azure.com on port 443, error: no error. (on Linux)

Open cosmarc opened this issue 3 years ago • 6 comments

I'm using IXWebSockets 11.4.3 (as client) to connect to my azure pub sub and I'm using the following code to do it so:

m_ws.setUrl(url.toStdString());
m_ws.addSubProtocol("protobuf.webpubsub.azure.v1");
m_ws.setPingInterval(45);
m_ws.enableAutomaticReconnection();
ix::SocketTLSOptions options;
options.certFile = "azure_wss.pem";
m_ws.setTLSOptions(options);

m_ws.setOnMessageCallback([this](const ix::WebSocketMessagePtr &msg) {
    switch (msg->type) {
    case ix::WebSocketMessageType::Message:
        qDebug() << "Message received:" << QString::fromStdString(msg->str);
        break;
    case ix::WebSocketMessageType::Open:
        onConnected();
        qDebug() << "Accepted protocol:" << QString::fromStdString(msg->openInfo.protocol);
        break;
    case ix::WebSocketMessageType::Close:
        onDisconnected();
        qDebug() << msg->closeInfo.code;
        qDebug() << QString::fromStdString(msg->closeInfo.reason);
        break;
    case ix::WebSocketMessageType::Error:
        qDebug() << "Error while connecting";
        qDebug() << "Error: "         << QString::fromStdString(msg->errorInfo.reason);
        qDebug() << "#retries: "      << msg->errorInfo.retries;
        qDebug() << "Wait time(ms): " << msg->errorInfo.wait_time;
        qDebug() << "HTTP Status: "   << msg->errorInfo.http_status;
        break;
    case ix::WebSocketMessageType::Ping:
        qDebug() << "Ping message received.";
        break;
    case ix::WebSocketMessageType::Pong:
        qDebug() << "Pong message received.";
        break;
    case ix::WebSocketMessageType::Fragment:
        qDebug() << "Fragment received.";
        break;
    default:
        qDebug() << "Unhandled message.";
        break;
    }
});

//.... Later on
m_ws.start();

When connecting, I get the following message: Error while connecting Error: "Unable to connect to gateway.webpubsub.azure.com on port 443, error: no error"

After digging into the source code it looks like it's either DNSLookup::resolve or SocketConnect::connectToAddress that fails. The same code works on Windows but fails to work on Ubuntu. I compiled on both platforms with TLS support using mbedTLS. Any help is much appreciated.

cosmarc avatar Jun 28 '22 08:06 cosmarc

Are you doing a static build of your code on linux ?

There is a know problem with dns resolution (actually it's a bit different, it leads to a segfault for this user) -> https://github.com/machinezone/IXWebSocket/issues/364

bsergean avatar Jun 30 '22 08:06 bsergean

No, my code is compiled dynamically and the lib is also compiled dynamically: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c54c391cb775f7d1117dc2dedb7b01352157c367, for GNU/Linux 3.2.0, not stripped

cosmarc avatar Jun 30 '22 09:06 cosmarc

I was gonna suggest to try with OpenSSL, but if the problem is during DNS resolution/connection, maybe it won't help.

I would still give it a try in lack of a better idea.

bsergean avatar Jun 30 '22 17:06 bsergean

You certainly moved on, but I checked today and I can't ping this domain.

$ ping protobuf.webpubsub.azure.v1
ping: cannot resolve protobuf.webpubsub.azure.v1: Unknown host

Is it a private host ?

bsergean avatar Sep 02 '22 04:09 bsergean

Ah sorry it was a sub-protocol ...

bsergean avatar Sep 02 '22 04:09 bsergean

Connecting to url: wss://gateway.webpubsub.azure.com
> Connection error: Expecting status 101 (Switching Protocol), got 403 status connecting to wss://gateway.webpubsub.azure.com, HTTP Status line: HTTP/1.1 403 Forbidden

I'm getting a 403, probably because I'm not authenticated, and I need a token in my url. But DNS resolution works for me (tested on mac).

bsergean avatar Sep 02 '22 04:09 bsergean