{"action":"created","issue":{"url":"https://api.github.com/repos/luin/ioredis/issues/56","labels_url":"https://api.github.com/repos/luin/ioredis/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/luin/ioredis/issues/56/comments","events_url":"https://api.github.com/repos/luin/ioredis/issues/56/events","html_url":"https://github.com/luin/ioredis/issues/56","id":83809782,"number":56,"title":"[cluster mode] inconsistent errors","user":{"login":"AVVS","id":1713617,"avatar_url":"https://avatars.githubusercontent.com/u/1713617?v=3","gravatar_id":"","url":"https://api.github.com/users/AVVS","html_url":"https://github.com/AVVS","followers_url":"https://api.github.com/users/AVVS/followers","following_url":"https://api.github.com/users/AVVS/following{/other_user}","gists_url":"https://api.github.com/users/AVVS/gists{/gist_id}","starred_url":"https://api.github.com/users/AVVS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AVVS/subscriptions","organizations_url":"https://api.github.com/users/AVVS/orgs","repos_url":"https://api.github.com/users/AVVS/repos","events_url":"https://api.github.com/users/AVVS/events{/privacy}","received_events_url":"https://api.github.com/users/AVVS/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-02T03:12:46Z","updated_at":"2015-06-02T05:10:22Z","closed_at":null,"body":"Cluster is created and then destroyed before and after the tests. So test runs are idempotent.\r\n\r\nFor some reason, sometimes redis cluster client instance doesn't have `sendCommand` on it and sometimes it does. I assume that context can be rewritten on retry or smth and become 'undefined'\r\n\r\n```sh\r\nVitalys-MacBook-Pro:mservice-users vitaly$ npm test\r\n\r\n> mservice-users@1.0.0 test /Users/vitaly/projects/mservice-users\r\n> BLUEBIRD_DEBUG=1 multi='list=- xunit=test-report.xml' ./node_modules/.bin/mocha -R mocha-multi --timeout 10000\r\n\r\n\r\n20:06:56 users: connected to rabbit@Vitalys-MacBook-Pro v3.5.2\r\n20:06:56 users: queue \"amq.gen-HS1YKx5rwxfoVL6TOyEKiA\" created\r\n20:06:56 users: queue \"amq.gen-HS1YKx5rwxfoVL6TOyEKiA\" binded to exchange \"test-mocha\" on route \"test.users.*\"\r\n  ․ actions#register() should fail on incorrect payload: 5ms\r\n  ․ actions#register() should create user, activate it, no captcha specified: 51ms\r\n  ․ actions#register() should reject creating user, because it already exists: 59ms\r\n  ․ actions#register() should fail when invalid captcha is passed: 36ms\r\n\r\n  4 passing (4s)\r\n\r\nVitalys-MacBook-Pro:mservice-users vitaly$ npm test\r\n\r\n> mservice-users@1.0.0 test /Users/vitaly/projects/mservice-users\r\n> BLUEBIRD_DEBUG=1 multi='list=- xunit=test-report.xml' ./node_modules/.bin/mocha -R mocha-multi --timeout 10000\r\n\r\n\r\n20:07:11 users: connected to rabbit@Vitalys-MacBook-Pro v3.5.2\r\n20:07:11 users: queue \"amq.gen-57pK5eobgqjeLt8s_IU7Cw\" created\r\n20:07:11 users: queue \"amq.gen-57pK5eobgqjeLt8s_IU7Cw\" binded to exchange \"test-mocha\" on route \"test.users.*\"\r\n  ․ actions#register() should fail on incorrect payload: 6ms\r\n  1) actions#register() should create user, activate it, no captcha specified\r\n  2) actions#register() should reject creating user, because it already exists\r\n  3) actions#register() should fail when invalid captcha is passed\r\n\r\n  1 passing (22s)\r\n  3 failing\r\n\r\n  1) actions#register() should create user, activate it, no captcha specified:\r\n     Uncaught TypeError: Cannot call method 'sendCommand' of undefined\r\n  ---------------------------------------------\r\n  ---------------------------------------------\r\n  ---------------------------------------------\r\n      at module.exports (lib/connectors/redis.js:12:21)\r\n      at module.exports (lib/service.js:106:9)\r\n      at Context.<anonymous> (test/register.js:56:52)\r\n      at exithandler (child_process.js:656:7)\r\n      at maybeClose (child_process.js:766:16)\r\n      at Socket.<anonymous> (child_process.js:979:11)\r\n      at Pipe.close (net.js:466:12)\r\n\r\n  2) actions#register() should reject creating user, because it already exists:\r\n     Error: timeout of 10000ms exceeded. Ensure the done() callback is being called in this test.\r\n  \r\n\r\n  3) actions#register() should fail when invalid captcha is passed:\r\n     Error: timeout of 10000ms exceeded. Ensure the done() callback is being called in this test.\r\n```\r\n\r\n```js\r\n// connectors/redis.js\r\n'use strict';\r\n\r\nvar redis = require('ioredis');\r\nvar instance;\r\n\r\nmodule.exports = function (config) {\r\n    if (instance) {\r\n        return instance;\r\n    }\r\n\r\n    instance = new redis.Cluster(config.redis.hosts, config.redis.options || {});\r\n    // forked version used with lazyConnect enabled\r\n    return instance.connect();\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/luin/ioredis/issues/comments/107810500","html_url":"https://github.com/luin/ioredis/issues/56#issuecomment-107810500","issue_url":"https://api.github.com/repos/luin/ioredis/issues/56","id":107810500,"user":{"login":"AVVS","id":1713617,"avatar_url":"https://avatars.githubusercontent.com/u/1713617?v=3","gravatar_id":"","url":"https://api.github.com/users/AVVS","html_url":"https://github.com/AVVS","followers_url":"https://api.github.com/users/AVVS/followers","following_url":"https://api.github.com/users/AVVS/following{/other_user}","gists_url":"https://api.github.com/users/AVVS/gists{/gist_id}","starred_url":"https://api.github.com/users/AVVS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AVVS/subscriptions","organizations_url":"https://api.github.com/users/AVVS/orgs","repos_url":"https://api.github.com/users/AVVS/repos","events_url":"https://api.github.com/users/AVVS/events{/privacy}","received_events_url":"https://api.github.com/users/AVVS/received_events","type":"User","site_admin":false},"created_at":"2015-06-02T05:10:22Z","updated_at":"2015-06-02T05:10:22Z","body":"Well, how do I make sure that cluster is connected?\r\n\r\nI've waited for 'ready' event, but it's emitted as soon as one node connects, but not the other.\r\n\r\nIn the pr what I basically do is add 'lazyConnect' to make sure that it actually connect, but it's one and the same with the 'ready' event.\r\n\r\nAssume the following code:\r\n\r\n```js\r\nvar redis = require('ioredis');\r\nvar instance = new redis.Cluster(hosts, { lazyConnect: true });\r\n\r\ninstance.connect().then(function () {\r\n   return instance.set(Date.now().toString(), 'somerandomvalue');\r\n});\r\n```\r\n\r\nI bet if you do this it will eventually throw the same error. I have to emphasize that I do wait for the ready event / connect resolve on my code"}}