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

Update deployments-rolling example to work with Ubuntu 18.04 and Node.js 10.x #124

Closed
geerlingguy opened this issue Jan 19, 2019 · 23 comments

Comments

@geerlingguy
Copy link
Owner

The demo-nodejs-api seems to have some issues installing and running under the latest LTS release of Node.js (10.x): https://github.com/geerlingguy/demo-nodejs-api

Basically, if you leave a Node.js app alone for more than 6 months or so, half the dependencies will go unmaintained and/or change names entirely (I'm looking at you, jade/pug!).

The example works under Ubuntu 14.04, but I am upgrading all my examples to at least 16.04 (in this case I would like to just go straight to 18.04), and I can't install Node.js 4.x or lower (which is compatible with the current nodejs-api demo app linked above) on Ubuntu 18.04... nor should I.

So for this ticket, I need to do some upstream work in the Node.js API demo app, to get it either rewritten or updated to work on modern Node.js, then test the full process on the deployments-rolling example.

@geerlingguy
Copy link
Owner Author

Upstream issue: geerlingguy/demo-nodejs-api#1

@geerlingguy
Copy link
Owner Author

Yay, also got tests passing in Travis CI again, on LTS + current.

@geerlingguy
Copy link
Owner Author

Testing locally.

@geerlingguy
Copy link
Owner Author

Build is failing inside the VM when it runs the tests on tag 2.0.0:

vagrant@nodejs1:/opt/demo-nodejs-api$ npm test

> examplenodejsapi@ test /opt/demo-nodejs-api
> mocha test --exit



restify listening at http://[::]:8080
  Hello
    /hello/:name endpoint
      ✓ returns a welcome message based on the name

  Ping
    /ping/:server endpoint
      ✓ tells us when a server is reachable
      1) tells us when a server is reachable

  2 passing (69ms)
  1 failing

  1) Ping
       /ping/:server endpoint
         tells us when a server is reachable:
     Uncaught Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at ServerResponse.setHeader (_http_outgoing.js:470:11)
      at ServerResponse.__send (node_modules/restify/lib/response.js:503:18)
      at ServerResponse.send (node_modules/restify/lib/response.js:316:21)
      at /opt/demo-nodejs-api/app.js:20:11
      at Socket.<anonymous> (node_modules/jjg-ping/lib/ping-system.js:82:25)
      at Socket.EventEmitter.emit (domain.js:441:20)
      at addChunk (_stream_readable.js:283:12)
      at readableAddChunk (_stream_readable.js:264:11)
      at Socket.Readable.push (_stream_readable.js:219:10)
      at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

@geerlingguy
Copy link
Owner Author

This is incredibly frustrating. On my Mac, I am getting no errors when running npm test. In the VM I get the error above. I've run through with a debugger and am not quite sure what's going on. Maybe a tiny minor version difference or something between brew-installed Node vs. the apt package from nodesource?

@geerlingguy
Copy link
Owner Author

Dependency tree via npm ls is identical, so it has to be a system difference. Tests are also passing on Node.js 10.x and 11.x on Travis CI: https://travis-ci.org/geerlingguy/demo-nodejs-api

Going to also test locally in the official node.js container.

@geerlingguy
Copy link
Owner Author

geerlingguy commented Jan 20, 2019

$ docker run --rm -it node /bin/bash
# cd /opt && git clone https://github.com/geerlingguy/demo-nodejs-api.git && cd demo-nodejs-api && npm install
# npm test

> examplenodejsapi@ test /opt/demo-nodejs-api
> mocha test --exit



restify listening at http://[::]:8080
  Hello
    /hello/:name endpoint
      ✓ returns a welcome message based on the name (50ms)

  Ping
    /ping/:server endpoint
      1) tells us when a server is reachable

  Ping
    /ping/:server endpoint
      ✓ tells us when a server is unreachable


  2 passing (2s)
  1 failing

  1) Ping
       /ping/:server endpoint
         tells us when a server is reachable:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/opt/demo-nodejs-api/test/ping.js)
  



npm ERR! Test failed.  See above for more details.

Drat. Looks like just running ping www.google.com is also failing to actually ping inside the container. From the outside, it works fine.

@geerlingguy
Copy link
Owner Author

Switching from Docker for Mac Edge to Docker for Mac Stable fixed the ping issue. Re-testing in node container.

@geerlingguy
Copy link
Owner Author

So in the Docker container it fails too:

# npm test

> examplenodejsapi@ test /opt/demo-nodejs-api
> mocha test --exit



restify listening at http://[::]:8080
  Hello
    /hello/:name endpoint
      ✓ returns a welcome message based on the name

  Ping
    /ping/:server endpoint
      ✓ tells us when a server is reachable (87ms)
      1) tells us when a server is reachable

  2 passing (124ms)
  1 failing

  1) Ping
       /ping/:server endpoint
         tells us when a server is reachable:
     Uncaught Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
      at ServerResponse.setHeader (_http_outgoing.js:482:11)
      at ServerResponse.__send (node_modules/restify/lib/response.js:503:18)
      at ServerResponse.send (node_modules/restify/lib/response.js:316:21)
      at /opt/demo-nodejs-api/app.js:20:11
      at Socket.<anonymous> (node_modules/jjg-ping/lib/ping-system.js:82:25)
      at Socket.EventEmitter.emit (domain.js:439:20)
      at addChunk (_stream_readable.js:288:12)
      at readableAddChunk (_stream_readable.js:269:11)
      at Socket.Readable.push (_stream_readable.js:224:10)
      at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)



npm ERR! Test failed.  See above for more details.

Weird. Something must be different locally :/

@geerlingguy
Copy link
Owner Author

The plot thickens; if I use docker run --rm -it node:8 /bin/bash it works. But locally, it's running Node 11.x... and in Travis it's doing 1.10.x and 1.11.x. What the heck?

@geerlingguy
Copy link
Owner Author

docker run --rm -it node:10 /bin/bash does not work.

@geerlingguy
Copy link
Owner Author

geerlingguy commented Jan 20, 2019

Docker Node.js image version Pass
6
8
9 ✖️
10 ✖️
lts
11
latest ✖️

Script to reproduce:

TEST_COMMAND="cd /opt && git clone https://github.com/geerlingguy/demo-nodejs-api.git && cd demo-nodejs-api && npm install && npm test"
for NODE_VERSION in "8" "9" "10" "11" "latest"; do echo "--- VERSION: $NODE_VERSION ---"; docker run --rm node:$NODE_VERSION /bin/bash -c "$TEST_COMMAND"; done

@geerlingguy
Copy link
Owner Author

How does node:11 work and node:latest not?! According to the Docker Hub docs (https://hub.docker.com/_/node/) they are identical... and the version is the same (v11.7.0).

@geerlingguy
Copy link
Owner Author

Now my mind is exploding—I just manually ran the test again with node:latest... and it passed.

And so I ran it on node:10 and that's passing too.

And so I ran it on node:9 and that's passing too.

I have a sneaking suspicion.

@geerlingguy
Copy link
Owner Author

I HATE YOU CHARTER SPECTRUM WITH AN UNDYING PASSION.

So it boils down to this: Charter Spectrum's DNS servers were not giving the correct response for an invalid domain, causing an error in the Ping class I'm using as part of the rest API. Apparently in the past few hours they fixed that problem and now I'm getting the correct answer cannot resolve gqtqM7eWGMeiQD2X: Unknown host.

So basically, the lesson is never use your ISP's DNS.

@dglinder
Copy link
Contributor

So, add step 0:
Ensure DNS settings are set to a non-brain-damaged server...

@geerlingguy
Copy link
Owner Author

@dglinder haha, yes. Exactly.

@geerlingguy
Copy link
Owner Author

So not only was that an issue... but after solving that I was still getting the error inside the Ubuntu 18.04 environment in Vagrant.

After another few hours debugging (even stepping through with Node's built-in debugger), I finally traced the error back to JJG-Ping... a library I wrote myself. Kudos to https://stackoverflow.com/a/9802084/100134 for the nudge in the right direction—I have to buffer the stdout from the ping call, otherwise the 'data' event can be called more than once in some weird situations, even for a very small data payload.

Opening an upstream issue...

@geerlingguy
Copy link
Owner Author

Testing a new tagged release. Upstream issue was geerlingguy/JJG-Node-Ping#3

@geerlingguy
Copy link
Owner Author

Oh what a rabbit hole that was. Sheesh.

@typ-ex
Copy link

typ-ex commented Jan 24, 2021

I couldn't get this to work on ubuntu 20.04.

Node.js API app tests task fails whenever the version changes and naturally gets skipped when the playbook is ran again.

@typ-ex
Copy link

typ-ex commented Jan 24, 2021

Vagrant ssh in and try npm test, and it comes back with a suggestion to install npm

@typ-ex
Copy link

typ-ex commented Jan 26, 2021

Oh. Maybe beyond what was already done here, it won't work on digitalocean's dns either.

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

3 participants