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

TypeError: Cannot read property 'node' of undefined #1

Closed
jamesbuckett opened this issue Mar 24, 2016 · 8 comments
Closed

TypeError: Cannot read property 'node' of undefined #1

jamesbuckett opened this issue Mar 24, 2016 · 8 comments

Comments

@jamesbuckett
Copy link

Hello.
.
Using this config.js

`var Etcd = require('node-etcd');

var etcdHost = process.env.ETCD_HOST || '172.17.42.1';
var etcdPort = process.env.ETCD_PORT || 4001;
console.log('Connecting to etcd on '+etcdHost+':'+etcdPort);
var etcd = new Etcd(etcdHost, etcdPort);

// Get all Rethinkdb servers from etcd
// We just need one for our connection
var rethinks = etcd.getSync("/services/rethinkdb", {recursive: true})

// Warning: Should add error checking / retry for production use

var nodes = rethinks.body.node.nodes;
nodes.forEach(function (node){
  console.log('Available rethinkdb server on', node.value);
});
var rethink = nodes[0].value;
console.log('Connecting to Rethinkdb on', rethink)

module.exports = {
  rethinkdb: {
    host: rethink,
    port: 28015,
    authKey: '',
    db: 'rethinkdb_ex'
  },
  express: {
     port: 3000
  }
};
`

I run these commands

I get the following error in the todo@1 log file

Mar 24 11:19:34 core-02 systemd[1]: Started ToDo Service.
Mar 24 11:19:35 core-02 docker[9170]: Connecting to etcd on 172.17.42.1:4001
Mar 24 11:21:41 core-02 docker[9170]: /src/config.js:14
Mar 24 11:21:41 core-02 docker[9170]: var nodes = rethinks.body.node.nodes;
Mar 24 11:21:41 core-02 docker[9170]: ^
Mar 24 11:21:41 core-02 docker[9170]: TypeError: Cannot read property 'node' of undefined
Mar 24 11:21:41 core-02 docker[9170]: at Object.<anonymous> (/src/config.js:14:26)
Mar 24 11:21:41 core-02 docker[9170]: at Module._compile (module.js:426:26)
Mar 24 11:21:41 core-02 docker[9170]: at Object.Module._extensions..js (module.js:444:10)
Mar 24 11:21:41 core-02 docker[9170]: at Module.load (module.js:351:32)
Mar 24 11:21:41 core-02 docker[9170]: at Function.Module._load (module.js:306:12)
Mar 24 11:21:41 core-02 docker[9170]: at Module.require (module.js:361:17)
Mar 24 11:21:41 core-02 docker[9170]: at require (module.js:380:17)
Mar 24 11:21:41 core-02 docker[9170]: at Object.<anonymous> (/src/app.js:6:14)
Mar 24 11:21:41 core-02 docker[9170]: at Module._compile (module.js:426:26)
Mar 24 11:21:41 core-02 docker[9170]: at Object.Module._extensions..js (module.js:444:10)
Mar 24 11:21:41 core-02 docker[9170]: at Module.load (module.js:351:32)
Mar 24 11:21:41 core-02 docker[9170]: at Function.Module._load (module.js:306:12)
Mar 24 11:21:41 core-02 docker[9170]: at Function.Module.runMain (module.js:467:10)
Mar 24 11:21:41 core-02 docker[9170]: at startup (node.js:117:18)
Mar 24 11:21:41 core-02 docker[9170]: at node.js:946:3
Mar 24 11:21:41 core-02 systemd[1]: todo@1.service: Main process exited, code=exited, status=1/FAILURE
Mar 24 11:21:41 core-02 docker[9636]: Error response from daemon: Cannot kill container todo-1: Container df90a15910eb219a081f845839c711a48ad1067c4c11f9707849b9febcb84de5 is not running
Mar 24 11:21:41 core-02 docker[9636]: Error: failed to kill containers: [todo-1]
Mar 24 11:21:41 core-02 docker[9651]: todo-1
Mar 24 11:21:41 core-02 systemd[1]: Stopped ToDo Service.
Mar 24 11:21:41 core-02 systemd[1]: todo@1.service: Unit entered failed state.
Mar 24 11:21:41 core-02 systemd[1]: todo@1.service: Failed with result 'exit-code'.

Thanks In Advance

@rosskukulinski
Copy link
Owner

Hi @jamesbuckett. Sorry for the confusion! The ToDo service uses rethinkdb as its datastore and there are two other services that you need to run first:
rethinkdb@.service and rethinkdb-announce@.service.

You should be able to submit & start one instance of rethinkdb using these commands:

fleetctl submit rethinkdb@.service rethinkdb-announce@.service
fleetctl start rethinkdb@1.service rethinkdb-announce@1.service

The rethinkdb@.service template runs an instance of the rethinkdb database, while rethinkdb-announce publishes the availability of that rethinkdb instance to etcd (which the ToDo app queries here)

I hope that helps! Let me know if you run into other problems.

@jameszh
Copy link

jameszh commented Mar 24, 2016

Ross,
I was having the same issue while rethinkdb and rethinkdb-announce were started and up, looked at inside todo@ container, no ETCD_HOST set, so added line in '-e ETCD_HOST=${COREOS_PUBLIC_IPV4}' to "docker run" in the todo@.service, it worked. I'm running "CoreOS stable (899.13.0)".

Thanks,
James

@rosskukulinski
Copy link
Owner

hi @jameszh. That's interesting. Normally I wouldn't expect ETCD_HOST to be set as an environmental variable -- I used that for local testing in a docker-compose environment.

Here I set var etcdHost = process.env.ETCD_HOST || '172.17.42.1';. Normally CoreOS exposes etcd on the docker network on 172.17.42.1, but maybe that isn't happening in your cluster?

@jameszh
Copy link

jameszh commented Mar 24, 2016

looks like is the case, my cluster (coreos-vagrant) doesn't have 172.17.42.1, no response from running following command. Must be related to new version of CoreOS.

core@core-01 ~ $ etcdctl -C '172.17.42.1:4001' ls

@rosskukulinski
Copy link
Owner

ahhhhh! yes that can happen in the default vagrant-coreos configuration because vagrant uses something like the 172.17.x.x subnet internally. I faintly remember mentioning that in the video tutorial series, but it would be good to have an errata / doc for that here

@rosskukulinski
Copy link
Owner

@jamesbuckett
Copy link
Author

Thank You Gentlemen

I had to apply both recommendations

  1. Edit the Vagrantfile and alter ip = "172.17.8.#{i+100}" to ip = "10.17.8.#{i+100}"
  2. vagrant destroy and vagrant up
  3. vi todo@.service and add -e ETCD_HOST=${COREOS_PUBLIC_IPV4}' to the RUN section

It is now working.

Thank you for your assistance.

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