{"action":"closed","issue":{"url":"https://api.github.com/repos/NodeRedis/node_redis/issues/1226","repository_url":"https://api.github.com/repos/NodeRedis/node_redis","labels_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/1226/labels{/name}","comments_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/1226/comments","events_url":"https://api.github.com/repos/NodeRedis/node_redis/issues/1226/events","html_url":"https://github.com/NodeRedis/node_redis/issues/1226","id":221953416,"number":1226,"title":"macOS sleep mode causes AbortError: Redis connection lost and command aborted. It might have been processed.","user":{"login":"loretoparisi","id":163333,"avatar_url":"https://avatars0.githubusercontent.com/u/163333?v=3","gravatar_id":"","url":"https://api.github.com/users/loretoparisi","html_url":"https://github.com/loretoparisi","followers_url":"https://api.github.com/users/loretoparisi/followers","following_url":"https://api.github.com/users/loretoparisi/following{/other_user}","gists_url":"https://api.github.com/users/loretoparisi/gists{/gist_id}","starred_url":"https://api.github.com/users/loretoparisi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loretoparisi/subscriptions","organizations_url":"https://api.github.com/users/loretoparisi/orgs","repos_url":"https://api.github.com/users/loretoparisi/repos","events_url":"https://api.github.com/users/loretoparisi/events{/privacy}","received_events_url":"https://api.github.com/users/loretoparisi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-15T15:02:25Z","updated_at":"2017-04-21T15:42:43Z","closed_at":"2017-04-21T15:42:43Z","body":"@BridgeAR The error full stack trace was\r\n\r\n```\r\n [Sat Apr 15 2017 16:20:08 GMT+0200 (CEST)] Error:\r\nAbortError: Redis connection lost and command aborted. It might have been processed.\r\n    at RedisClient.flush_and_error (/webservice/node_modules/redis/index.js:357:23)\r\n    at RedisClient.connection_gone /webservice/node_modules/redis/index.js:659:14)\r\n    at RedisClient.on_error (/webservice/node_modules/redis/index.js:405:10)\r\n    at Socket.<anonymous> (/webservice/node_modules/redis/index.js:279:14)\r\n    at emitOne (events.js:96:13)\r\n    at Socket.emit (events.js:188:7)\r\n    at emitErrorNT (net.js:1278:8)\r\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\r\n    at process._tickDomainCallback (internal/process/next_tick.js:122:9)\r\n```\r\n\r\nMy question here if there is a recovery procedure to restore the connection as soon as the network become stable again.\r\n\r\nTwo cases when this error is generated are\r\n\r\n* You run the redis over a VPN and the VPN connection goes away and then back - see https://github.com/NodeRedis/node_redis/issues/1216\r\n\r\n* You are testing your backend, your local computer enters SLEEP mode: when you return from sleep energy saving mode, and try to connect to your service, redis will return this error, even if your network connection was up: is this due to a active connection put in \"hold\" by redis (?).\r\n\r\nSupposed that we are in the second case (local computer in sleep mode), how to recover for sleep mode in the redis client?\r\n\r\nMy default retry strategy was:\r\n\r\n```javascript\r\nretry_strategy: function (options) {\r\n                    \r\n                    self.logger.warn(\"RedisStore.retryStragegy %@\", options);\r\n\r\n                    if (options && options.error && options.error.code === 'ECONNREFUSED') {\r\n                        // End reconnecting on a specific error and flush all commands with a individual error\r\n                        return new Error('The server refused the connection');\r\n                    }\r\n                    if (options && options.total_retry_time > 1000 * 60 * 60) {\r\n                        // End reconnecting after a specific timeout and flush all commands with a individual error\r\n                        return new Error('Retry time exhausted');\r\n                    }\r\n                    if (options && options.times_connected > 10) {\r\n                        // End reconnecting with built in error\r\n                        return undefined;\r\n                    }\r\n                    // the reconnect retry will happen exactly after this time in milliseconds\r\n                    return Math.max(options.attempt * 100, 3000);\r\n                }\r\n```\r\n\r\nand I have this setup:\r\n\r\n```javascript\r\n{\r\n/** key default expire */\r\n                expire: 60 * 60 * 24,\r\n\r\n                /**\r\n                 * If set to true, the keep-alive functionality is enabled on the underlying socket.\r\n                 */\r\n                socket_keepalive : true\r\n}\r\n```\r\n\r\nMy strategy was then this\r\n\r\n```javascript\r\nfunction handleError(results,error) {\r\n                if( error && (error.code == 'NR_CLOSED' || error.code == 'UNCERTAIN_STATE')) { // connection closed, try reconnect\r\n                    self._initRedisStore()\r\n                    .then(ok=> { // store connected\r\n                        if(results) return resolve(results);\r\n                        else return execute(params,resolve,reject);\r\n                    })\r\n                    .catch(error => { // store connect error\r\n                        if(results) return resolve(results);\r\n                        else return execute(params,resolve,reject);\r\n                    });\r\n                } else if( error && (error.code == 'ETIMEDOUT')) { // timed out\r\n                    return execute(params,resolve,reject);\r\n                } else {\r\n                    self.store.unset(cacheKey)\r\n                    .then(result => {\r\n                        return execute(params,resolve,reject);\r\n                    })\r\n                    .catch(error => { // store unset ERROR\r\n                        return execute(params,resolve,reject);\r\n                    });\r\n                }\r\n            }\r\n```\r\n\r\nwhen `_initRedisStore` re-initialize the store when the error code was `NR_CLOSED` or `NR_CLOSED`. Shall I have to consider a `ETIMEDOUT` here as well? I have not used it there, since in case of host computer sleep I thought the error should have been a connection close error, not a timeout error, that should happen when a active connection timed out.\r\n\r\nDoes it makes sense to handle this error as a `ETIMEDOUT` for a dangling connection when the host is exiting the sleep mode?"}}
{"actor":{"display_login":"BridgeAR"}}