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

Connect via HTTP to a WS Endpoint? #1123

Closed
DanielCh58 opened this issue Apr 26, 2020 · 11 comments
Closed

Connect via HTTP to a WS Endpoint? #1123

DanielCh58 opened this issue Apr 26, 2020 · 11 comments

Comments

@DanielCh58
Copy link

Hello,

does it make sense to connect to a WebSocked Enpoint via HTTP GET Request? What exactly should this do?
I use websocket instead of BOSH to connect from Jitsi Web Page too prosody XMPP Server.

The only thing I get is an error 500 on Apache and in the logfile:

SourceCode: XmppConnection.js#L328

ApacheLogfile with Error 500

"GET /xmpp-websocket?room=test500 HTTP/2.0" **500** 618 "https://meet.example.de/test500" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.163 Chrome/80.0.3987.163 Safari/537.36"

My Apache conf for this URL

## XMPP via WebSocket
ProxyPass "/xmpp-websocket" "ws://localhost:5280/xmpp-websocket"
ProxyPassReverse "/xmpp-websocket" "ws://localhost:5280/xmpp-websocket"

And on Chrome Console:

XmppConnection.js:330 GET https://meet.gymnasiumsteglitz.de/xmpp-websocket?room=test500 500
Logger.js:154 2020-04-26T17:17:46.003Z [modules/xmpp/XmppConnection.js] <d._maybeStartWSKeepAlive>:  Scheduling next WebSocket keep-alive in 133734.4168300808ms
XmppConnection.js:330 GET https://meet.gymnasiumsteglitz.de/xmpp-websocket?room=test500 500
Logger.js:154 2020-04-26T17:20:00.551Z [modules/xmpp/XmppConnection.js] <d._maybeStartWSKeepAlive>:  Scheduling next WebSocket keep-alive in 178128.69091464055ms

Curl Prosody also dont like this request:

curl -s "http://127.0.0.1:5280/xmpp-websocket/"
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><style>body{margin-top:14%;text-align:center;background-color:#F8F8F8;font-family:sans-serif;}h1{font-size:xx-large;}p{font-size:x-large;}p+p { font-size: large; font-family: courier }</style>
</head>
<body><h1>404 Not Found</h1><p>Whatever you were looking for is not here. It's behind you.</p><p>Unknown host: 127.0.0.1</p>
</body>
</html>
@damencho
Copy link
Member

you.

Unknown host: 127.0.0.1

There is no such virtual host configured in prosody.

Please use the community forum when you have questions or problems before opening new issues.

@DanielCh58
Copy link
Author

Sorry for be unpresize. But the core of my question leave unanserwed. Yes I can try to use the forum next time.

@damencho
Copy link
Member

The code you are showing is something that is running on meet.jit.si at the moment using websockets, you can try debugging it and see how it works. I pointed you the reason for the error you see, I think the problem is webserver config using localhost as host when proxing the request
https://github.com/jitsi/jitsi-meet/blob/94a15914d037fa388aa022c7e8ede318368b8ae0/doc/debian/jitsi-meet/jitsi-meet.example#L74 This is how it is done in nginx, if you are using Apache I don't know.

@DanielCh58
Copy link
Author

Thanks for your answer. I created a Forumentry 45407
Yes I changed the Hostname for the curl request, and prosody gave me the same answer as on meet.jit.si.

I'm sure I can also figure this out for apache, but my origin question is why.

Why a websocket needs a HTTP GET Request? Websocket should be open for a long time. Especially if there are messages, and there are a lot of messages.

If your are using BOSH it may make sense, but not for WebSocket from my Point of view. The linked sourcecode shows how the url will be transformed from wss:// to https:// but this a different protocoll. (Yes I know websocket based on http)

Currently I solved the problem setting websocketKeepAlive to 0, so the LibJitsi will not try to make keepAlive for websocket.

@sapkra
Copy link
Contributor

sapkra commented Nov 26, 2020

I came across the same problem. Because it is trying to connect to an ws endpoint via http, the response is not correct which results in a lot of errors. I don't understand why sending new http request should affect a keep-alive for another connection with even another protocol.

Access to fetch at 'https://my.domain/xmpp-websocket?token=mytoken' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

GET https://my.domain/xmpp-websocket?token=mytoken net::ERR_FAILED

[modules/xmpp/XmppConnection.js] Websocket Keep alive failed for url: https://my.domain/xmpp-websocket?token=mytoken {error: TypeError: Failed to fetch}

This is set to true and the websocket connection is working fine.

cross_domain_websocket = true

@damencho Does it not make more sense to send ping/pong messages via the websocket connection and enable auto reconnect.

@saghul
Copy link
Member

saghul commented Nov 26, 2020

Not sure I understand (damencho is out for the week). Who is starting the bogus connection?

@sapkra
Copy link
Contributor

sapkra commented Nov 26, 2020

You know that I built this mattermost plugin. So the mattermost servers which are using this plugin are not under my domain but are communicating with my jitsi instance. After switching to websockets I have the problem that the the websocket connection works fine but all the keep-alive requests are failing because of CORS.

I'm still wondering why lib-jitsi-meet is sending HTTP GET requests to keep a websocket connection alive. This seems to be the root cause. I'm not using nginx as a proxy but I don't think that this is causing any issues.

wss://my.domain/xmpp-websocket?token=mytoken

Request headers
GET wss://my.domain/xmpp-websocket?token=mytoken HTTP/1.1
Host: my.domain
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
Upgrade: websocket
Origin: http://localhost
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,de;q=0.7
Sec-WebSocket-Key: 544nE1Gw8RwUnWfJ9Z2jjQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: xmpp
Response headers
HTTP/1.1 101 Switching Protocols
Date: Thu, 26 Nov 2020 08:54:50 GMT
Connection: Upgrade
Content-Length: 0
Sec-WebSocket-Accept: t8ur/XyO58IIRfatPsahia7Ap2A=
Upgrade: websocket
Sec-WebSocket-Protocol: xmpp

https://my.domain/xmpp-websocket?token=mytoken -> CORS error

Request headers
GET /xmpp-websocket?token=mytoken HTTP/1.1
Host: my.domain
Connection: keep-alive
sec-ch-ua: "Google Chrome";v="87", "\"Not;A\\Brand";v="99", "Chromium";v="87"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
Accept: */*
Origin: http://localhost
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,de;q=0.7
Response headers (might be different because of CORS error)
HTTP/1.1 200 OK
Date: Thu, 26 Nov 2020 08:56:29 GMT
Content-Length: 169
Content-Type: text/html
Set-Cookie: d84f69e4d6a5efe7db8f4b414640e599=f9c5e62fa497ce81f616c50b0fb11395; path=/; HttpOnly; Secure
Cache-control: private

@saghul
Copy link
Member

saghul commented Nov 26, 2020

Ah I see. IIRC that was done as a keep-alive mechanism, so load balancers would keep the room association open. We should probably change that to HEAD, but not sure that'd break things.

@renepardon
Copy link

renepardon commented Dec 25, 2020

Having the same problem but the flags are already set in prosody (v0.11.7 which is running behind nginx reverse-proxy) configuration:

cross_domain_bosh = true;
cross_domain_websocket = true;
consider_bosh_secure = true;
consider_websocket_secure = true;

So there is a CORS problem and:

[modules/xmpp/XmppConnection.js] <eval>: Websocket Keep alive failed for url: https://mydomain.org/xmpp-websocket

with the error: error: TypeError: Failed to fetch

@zamarawka
Copy link

@renepardon did you find any solution for this? I having same problem with docker-jitsi-meet setup and this is the only issue I found about this.
I host jitsi on sub-domain and keep alive failing with cors errors.

@sapkra
Copy link
Contributor

sapkra commented May 22, 2021

Currently I solved the problem setting websocketKeepAlive to 0, so the LibJitsi will not try to make keepAlive for websocket.

@zamarawka

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

6 participants