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

bugfix: add error handle to redis adapter to avoid unexpected exit. #55

Merged
merged 1 commit into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ module.exports = app => {
}

if (config.redis) {
app.io.adapter(redis(config.redis));
const adapter = redis(config.redis);
// https://github.com/socketio/socket.io-redis/issues/21
adapter.prototype.on('error', err => {
app.coreLogger.error(err);
});
app.io.adapter(adapter);
debug('[egg-socket.io] init socket.io-redis ready!');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

exports.io = {
redis: {
host: '127.0.0.1',
port: 6666,
},
};

exports.keys = '123';
4 changes: 4 additions & 0 deletions test/fixtures/apps/socket.io-test-redis-error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "socket.io-test-redis-error",
"version": "0.0.1"
}
19 changes: 19 additions & 0 deletions test/io.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,25 @@ describe('test/socketio.test.js', () => {
}, 500);
});
}

it('redis connection error', done => {
const appName = 'socket.io-test-redis-error';
const app = mm.cluster({
baseDir: `apps/${appName}`,
workers: 2,
sticky: true,
});
app.ready().then(() => {
setTimeout(() => {
app.close()
.then(() => {
const errorLog = getErrorLogContent(appName);
assert(contains(errorLog, 'connect ECONNREFUSED 127.0.0.1:6666') > 0);
})
.then(done, done);
}, 300);
});
});
});

describe('namespace', () => {
Expand Down