openhab-cloud icon indicating copy to clipboard operation
openhab-cloud copied to clipboard

504 Gateway Time-out on REST PUT

Open tsheldon opened this issue 8 years ago • 14 comments

Summary: Attempting to use the paper-ui remotely through myopenhab to modify a few channels, and it appears that most of the paper-ui works fine, except for PUTs.

Tried issuing the same post through the REST docs ui, but end up with the same response.

The paper-ui works fine when locally, so this appears likely to be bug with the routing rules between the nginx accepting frontend and whatever service is relaying that post back to the local instance.

Sanitized Request headers:

PUT /rest/links/zwave_device_963cad32_node37_meter_watts/zwave:device:963cad32:node37:meter_watts HTTP/1.1
Host: home.myopenhab.org
Connection: keep-alive
Content-Length: 111
Authorization: Basic <redacted>
Accept: application/json, text/plain, */*
Origin: https://home.myopenhab.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: https://home.myopenhab.org/paperui/index.html
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
Cookie: <redacted>

Response:

HTTP/1.1 504 Gateway Time-out
Server: nginx/1.10.0 (Ubuntu)
Date: Thu, 19 Jan 2017 16:28:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 594
Connection: keep-alive

tsheldon avatar Jan 19 '17 19:01 tsheldon

I have a similar problem. I use openhab cloud behind a apache reverse proxy and when I watch the Networkcomunication with the firefox Developementtools I see this returned by the proxy for the PUT requests.

Proxy Error

The proxy server received an invalid response from an upstream server. The proxy server could not handle the request PUT /rest/items/sss.

Reason: Error reading from remote server

Apache/2.4.18 (Ubuntu) Server at MyDomain.com Port 443

hiFloh avatar May 17 '17 21:05 hiFloh

Yep same behaviour when I try and do a put for example change config of a binding ....

PUT /rest/services/org.openhab.openhabcloud/config HTTP/1.1
Host: home.myopenhab.org
Connection: keep-alive
Content-Length: 75
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
Origin: https://home.myopenhab.org
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36
Content-Type: application/json
Referer: https://home.myopenhab.org/paperui/index.html
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-GB,en;q=0.8,de;q=0.6,fr;q=0.4,lb;q=0.2
Cookie: <obscured>
HTTP/1.1 504 Gateway Time-out
Server: nginx/1.10.0 (Ubuntu)
Date: Wed, 24 May 2017 06:16:54 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 594
Connection: keep-alive

petzlux avatar May 24 '17 06:05 petzlux

This still doesnt work. Can someone tell us if this can get fixed, or even be reproduced by the devs?

petzlux avatar Jun 19 '17 11:06 petzlux

Looks like the culprit is the bodyParser in app.js ~ line 207 207> app.use(bodyParser.json());

preassembleBody in routes/index.js is expecting events that are not firing, causing the timeout.

PaulBaugher avatar Sep 06 '17 17:09 PaulBaugher

@petzlux,

I will take a look soon. Sorry was mad busy! Thanks for being patient

marziman avatar Sep 06 '17 18:09 marziman

So just commenting that out only fixed the PUT and broke some other things. A workaround is to leave that line in app.js alone and to modify the /routes/index.js preassembleBody function. Prepend the following to the function body.

if (req._body) { req.rawBody=JSON.stringify(req.body); next(); return; }

A more long term solution would be to probably just use the bodyParser in its entirety and to remove preassembleBody altogether.

PaulBaugher avatar Sep 06 '17 18:09 PaulBaugher

I also have the same issue, with RPI3 + clean openhabian. I basically can't do anything that requires saving (like changing configuration) through myopenhab. Directly through http://openhabianpi:8080 it works perfectly.

Isn't it happen to everyone? Looks kind of a big issue to me :S...

mahonni avatar Nov 20 '17 15:11 mahonni

Same behaviour as @mahonni with RPI3 + clean openhabian. No further proxies. Cost me two hours today. :-(

spacemanspiff2007 avatar Dec 31 '17 13:12 spacemanspiff2007

I have the same problem on multiple openhab instances where i can't edit, add, or remove anything by using myopenhab.org. When trying to use the save button nothing happens for a while and then throws a 504 - gateway time-out. When connected locally to the openhab instance everything works perfect..

Any update on this issue?

marcom010 avatar Feb 06 '18 14:02 marcom010

Same issue here. I can confirm that @PaulBaugher 's fix does work if you run your own openHAB cloud instance as detailed here: https://community.openhab.org/t/setup-your-own-openhab-cloud-myopenhab-server-instance/24716

qfluxlab avatar Feb 17 '18 15:02 qfluxlab

Hi, yes that seems like an issue at indexjs. I will go on this as next on my backlog. Sorry for the delay and thanks for your patience guys.

I will keep you updated for a fix.

marziman avatar Mar 19 '18 22:03 marziman

This is fixed in #170 , but is not deployed. I think this weekend would be a good time to do so as I'm out of town until then.

digitaldan avatar Mar 19 '18 22:03 digitaldan

Thanks, this fix was extremely necessary

mahonni avatar Mar 27 '18 14:03 mahonni

Hi, if I'm not mistaken #170 is still not deployed to home.myopenhab.org. Could you please think about it? ;) Thanks ❤️

ghys avatar Apr 03 '18 19:04 ghys