deis / router

Edge router for Deis Workflow

Home Page:https://deis.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

502 error in proxying WebSockets.

monaka opened this issue · comments

I'm implementing SSO gateway for Eclipse/Che (cluoud IDE). It uses WebSockets.
I implemented small proxy written in Node.js (named eclipse-che-gw) and deployed.
And I'm facing 502 error on Router. Log is like this. Domains are fake.

2016/10/03 04:01:25 [error] 81#0: *109878 upstream prematurely closed connection while reading response header from upstream, client: 172.16.85.1, server: ~^eclipse-che-gw\.(?<domain>.+)$, request: "GET /api/ws/workspacelxh2a8qnvl472zdj HTTP/1.1", upstream: "http://172.17.0.235:80/api/ws/workspacelxh2a8qnvl472zdj", host: "eclipse-che-gw.deis.example.com"
[2016-10-03T04:01:25+00:00] - eclipse-che - 172.16.85.1 - - - 502 - "GET /api/ws/workspacelxh2a8qnvl472zdj HTTP/1.1" - 732 - "-" - "Mozilla/5.0 (X11; CrOS x86_64 8530.81.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.103 Safari/537.36" - "~^eclipse-che-gw\x5C.(?<domain>.+)$" - 172.17.0.235:80 - eclipse-che-gw.deis.example.com - 0.339 - 0.339

My cluster is on Azure F2s x 4. All nodes are healthy.
The result of free on the node which runs Router.
Surely it's not rich but not too poor, I believe.

             total       used       free     shared    buffers     cached
Mem:       4043104    3871988     171116       1464     167820    1391040
-/+ buffers/cache:    2313128    1729976
Swap:      8388604     160272    8228332

I connect to the backend pod running Che directly and browsed. There looks fine.

It is sane nginx.conf generated by Rrouter.

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

502 error is reproduced only WebSocket connections. HTTP connections are fine.
Are there any more check points and/or tuning points available?

My app is like this. It is almost same as official example code.

var http      = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({
        target: {
                host: 'eclipse-che.default.svc.cluster.local',
                port: 8080
        }
});
var proxyServer = http.createServer(function (req, res) {
        proxy.web(req, res);
});

proxyServer.on('upgrade', function(req, socket, head) {
        proxy.ws(req, socket, head);
});
proxy.listen(process.env.PORT || 5000);

It seems deis scale web=2 is not effective in my case.

Is your SSO application built with a build pack? Are are you using another workflow like pushing a Dockerfile or a pre-built image?

At the first, I suspected this is a performance setting issue (like timeout). But it seems the root cause is CORS or something.
I close this for now. And may re-open in case it requires to add something to nginx.conf.

I got it completely. The root causes are a bug in my script and Che's issue. Router is clean.

- proxy.listen(process.env.PORT || 5000);
+ proxyServer.listen(process.env.PORT || 5000);