burnedikt / diasend-nightscout-bridge

Synchronize your diasend data to nightscout.
MIT License
18 stars 18 forks source link

Google Cloud:502 Bad Gateway error #35

Closed Jason-Burke closed 1 year ago

Jason-Burke commented 1 year ago

My objective was to deploy Nightscout on Google Cloud with the Diasend Nightscout Bridge as a plug-in.

I followed the largely automated process described by the Xdrip development team here to prepare, install and configure Nightscout for Google Cloud.

After completing steps 1 through 5, I had functioning Nightscout instance.

I then leveraged option 11 "Customize Nightscout" to install the cgm-remote-monitor fork located here from burnedikt repository which includes the diasend-nightscout-bridge merged. For reference, the script that drives the process can be viewed here.

Once complete, I observed only the usual warnings but NO errors. Unfortunately, I now get the "502 Bad Gateway".

From the nginx error log:

2023/01/09 05:17:49 [error] 692#692: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET /sw.js HTTP/1.1", upstream: "http://127.0.0.1:1337/sw.js", host: "window.jumpingcrab.com", referrer: ""
2023/01/09 05:17:49 [error] 692#692: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "window.jumpingcrab.com", referrer: "https://window.jumpingcrab.com/sw.js"
2023/01/09 05:17:51 [error] 692#692: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET /sw.js HTTP/1.1", upstream: "http://127.0.0.1:1337/sw.js", host: "window.jumpingcrab.com", referrer: ""
2023/01/09 05:22:10 [error] 692#692: *12 connect() failed (111: Connection refused) while connecting to upstream, client: 51.81.167.146, server: window.jumpingcrab.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "window.jumpingcrab.com"
2023/01/09 05:24:04 [error] 692#692: *14 connect() failed (111: Connection refused) while connecting to upstream, client: 194.55.186.216, server: _, request: "POST /boaform/admin/formLogin HTTP/1.1", upstream: "http://127.0.0.1:1337/boaform/admin/formLogin", host: "34.127.12.184:80", referrer: "http://34.127.12.184:80/admin/login.asp"
2023/01/09 05:32:30 [error] 692#692: *16 connect() failed (111: Connection refused) while connecting to upstream, client: 162.243.147.29, server: window.jumpingcrab.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "34.127.12.184"
2023/01/09 05:34:43 [error] 692#692: *18 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "window.jumpingcrab.com", referrer: "https://window.jumpingcrab.com/sw.js"
2023/01/09 05:34:44 [error] 692#692: *18 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "window.jumpingcrab.com", referrer: "https://window.jumpingcrab.com/sw.js"
2023/01/09 05:34:44 [error] 692#692: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET /sw.js HTTP/1.1", upstream: "http://127.0.0.1:1337/sw.js", host: "window.jumpingcrab.com", referrer: ""
2023/01/09 05:34:45 [error] 692#692: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 1.145.158.232, server: window.jumpingcrab.com, request: "GET /sw.js HTTP/1.1", upstream: "http://127.0.0.1:1337/sw.js", host: "window.jumpingcrab.com", referrer: ""

It looks like Nightscout does not start. I then ran the Nightscout-start shell script which yielded:

`API_SECRET has 141 bits of entropy
Executing startBoot
Executing checkNodeVersion
Node LTS version v10.19.0 is supported
Executing checkEnv
Executing augmentSettings
Parsing config URL from IMPORT_CONFIG failed
Executing checkSettings
Checking settings
Executing setupStorage
Setting up new connection to MongoDB
Successfully established connection to MongoDB
Mongo user role seems ok: [ { role: 'readWrite', db: 'Nightscout' } ]
Mongo Storage system ready
Executing setupAuthorization
Executing setupInternals
Pushover was NOT configured
Executing ensureIndexes
Ensuring indexes
....... < SNIPPED FOR BREVITY > ......
Executing setupListeners
Executing setupBridge
Dexcom bridge not enabled
Executing setupMMConnect
MiniMed Connect not enabled
Executing setupDiasend
/nightscout_start/cgm-remote-monitor/node_modules/http-cookie-agent/dist/create_cookie_agent.js:16
        jar;
           ^

SyntaxError: Unexpected token ;
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/nightscout_start/cgm-remote-monitor/node_modules/http-cookie-agent/dist/index.js:4:29)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)`

Any suggestions warmly welcome!

burnedikt commented 1 year ago

This seems like the exact same issue also @muthijammy was having here.

Back then, I couldn't really make sense of it, but from your logs, I can see that the google cloud machine appears to be using NodeJS 10.19.0 which is super ancient and reached end of life in April, 2021. This project has only been tested on NodeJS versions 12, 14 and 16, which are the versions that nightscout officially supports.

I would assume that the NodeJS version is the issue here. One way forward would be to either upgrade the nodejs version on the machine (or trying to use a newer ubuntu version for the virtual machine like 22.04 which might come with a newer nodejs version out of the box) or use a different hosting provider for nightscout like e.g. railway.

burnedikt commented 1 year ago

Indeed I was able to reproduce this issue using nodejs 10 and I was also able to confirm that running the xdrip installer for nightscout will actually only install nodejs version 10 on a ubuntu 20.04 VM. So right now, the only way is to upgrade to a newer nodejs version (12, 14 or 16) on the machine.

Jason-Burke commented 1 year ago

Thanks Benedikt. I created a new VM (22.04) to no avail, the process was halted by pre-requisite screening. I also tried updating Node to v16.x.x LTS on the 20.04 VM, again to no avail. Nighscout continued however I do not think the plug-in had started despite the Node upgrade.

In the end, I relented and moved to Railway. Everything is now operational as you would expect.

Thanks again for the troubleshooting, guidance and offering potential remediation steps.