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

由于redis服务器网络异常,egg进程被强制退出 #3731

Closed
bhb4157 opened this issue May 29, 2019 · 9 comments
Closed

由于redis服务器网络异常,egg进程被强制退出 #3731

bhb4157 opened this issue May 29, 2019 · 9 comments

Comments

@bhb4157
Copy link

bhb4157 commented May 29, 2019

项目里面使用了egg-socket.io,package.json里面的启动命令如下:

EGG_SERVER_ENV=prod egg-scripts start --sticky --port=10006 --daemon

redis服务出现网络异常时,egg会尝试重连几次,但最后连接不上后,egg服务就退出了。
出现异常时的错误日志:

2019-05-29 01:19:51,044 ERROR 30602 nodejs.AbortError: Ready check failed: Redis connection lost and command aborted. It might have been processed. (uncaughtException throw 27 times on pid:30602)
at RedisClient.flush_and_error (/datadisk/socket-egg-server/node_modules/redis/index.js:362:23)
at RedisClient.connection_gone (/datadisk/socket-egg-server/node_modules/redis/index.js:664:14)
at Socket. (/datadisk/socket-egg-server/node_modules/redis/index.js:289:14)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at TCP._handle.close [as _onclose] (net.js:557:12)
code: "UNCERTAIN_STATE"
command: "INFO"
pid: 30602
hostname: VM_4_89_centos

2019-05-29 01:20:09,699 ERROR 30602 nodejs.ECONNRESETError: read ECONNRESET
at _errnoException (util.js:992:11)
at TCP.onread (net.js:618:25)
code: "ECONNRESET"
errno: "ECONNRESET"
syscall: "read"
name: "ECONNRESETError"
pid: 30602
hostname: VM_4_89_centos

2019-05-29 01:20:14,318 ERROR 30594 nodejs.ECONNRESETError: read ECONNRESET
at _errnoException (util.js:992:11)
at TCP.onread (net.js:618:25)
code: "ECONNRESET"
errno: "ECONNRESET"
syscall: "read"
name: "ECONNRESETError"
pid: 30594

@dead-horse
Copy link
Member

启动时 redis 如果连接不通的话是无法启动的。现在 socket-io 多实例部署是强依赖 redis 的,redis 挂了 socket-io 也无法正常使用。

@Lizhooh
Copy link

Lizhooh commented Jun 18, 2019

redis 挂了就算运行着也没用啊

@atian25 atian25 closed this as completed Jun 18, 2019
@ngot
Copy link
Member

ngot commented Jun 19, 2019

socket.io 启用 Redis 的话,那就是强依赖,无法连通的话,服务将无法工作。所以这里必须连通成功才能启动,否则启动的起来的一个无法工作的服务,更让人困惑。

@bhb4157
Copy link
Author

bhb4157 commented Jun 19, 2019

socket.io 启用 Redis 的话,那就是强依赖,无法连通的话,服务将无法工作。所以这里必须连通成功才能启动,否则启动的起来的一个无法工作的服务,更让人困惑。

这次只是云服务器网络异常导致redis连接不上,影响时间本来就不到两分钟,但是是在凌晨,由于服务被强制停止,即使redis网络恢复服务还是不能用。还好这次只是一台,如果是上百台服务因为redis异常被停止问题就更加严重。所以还是觉得强依赖的话不合理,因为有检测机制,至少应该开发人员可以配置才好

@ngot
Copy link
Member

ngot commented Jun 19, 2019

@bhb4157 明白问题了,是运行时异常退出,并不是启动时异常退出。我来看看怎么解决。

@ngot ngot reopened this Jun 19, 2019
@bhb4157
Copy link
Author

bhb4157 commented Jun 19, 2019

@bhb4157 明白问题了,是运行时异常退出,并不是启动时异常退出。我来看看怎么解决。

多谢了,还有就是我后续测试,redis服务关闭确实会导致egg服务退出,退出前会重试连接redis大概30次左右,然后就退出了

@ngot
Copy link
Member

ngot commented Jun 19, 2019

eggjs/egg-socket.io#55 这个 PR 应可以修复 Redis 断开后,服务退出的问题。

@ngot
Copy link
Member

ngot commented Jun 19, 2019

同时我发现,socket.io 可以使用 ioredis 的 https://github.com/socketio/socket.io-redis/blob/master/README.md#with-ioredis-client, 所以有办法可以使用 https://github.com/eggjs/egg-redis 来提供 Redis 配置服务。

等我有时间了,我来搞一下这个。

@ngot
Copy link
Member

ngot commented Jun 20, 2019

  • egg-socket.io@4.1.6

@ngot ngot closed this as completed Jun 20, 2019
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

5 participants