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

egg-socket.io sticky mode bug. #1034

Closed
shyser opened this issue Jun 12, 2017 · 18 comments
Closed

egg-socket.io sticky mode bug. #1034

shyser opened this issue Jun 12, 2017 · 18 comments

Comments

@shyser
Copy link

shyser commented Jun 12, 2017

  • Node Version: 8.0.0
  • Egg Version: 1.4.0
  • Plugin Name: egg-socket.io
  • Plugin Version: 1.2.2
  • Platform: Ubuntu 16.04
  • Mini Showcase Repository:

egg-socket.io由于#997而退回到了 1.x 。

错误日志:

2017-06-12 13:30:47,102 ERROR 25808 nodejs.TypeError: Cannot read property 'emit' of null (uncaughtException throw 1 times on pid:25808)
    at Socket.socketOnTimeout (_http_server.js:386:34)
    at emitNone (events.js:105:13)
    at Socket.emit (events.js:207:7)
    at Socket._onTimeout (net.js:401:8)
    at ontimeout (timers.js:488:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:283:5)

复现步骤:

  1. 用脚手架创建一个项目;
  2. 添加egg-socket.io插件;
  3. 启动参数里添加sticky: true
  4. 启动程序,访问127.0.0.1:7001,5秒钟之后出现错误提示。

补充说明:
我的项目在node 7.x 添加上sticky参数是正常的。前几天升了node 8,重新安装了node_modules,然后就出了这个问题。事实上,如果我不添加sticky的话,是没有这个报错的,但是官方文档上明确说过需要启用sticky mode的。我对这个sticky不咋了解,所以很不放心。

@ngot
Copy link
Member

ngot commented Jun 12, 2017

sticky: true 是 socket.io 能够工作的基础。不加是直接无法工作的。

具体的问题,提交个可复现的最简代码仓库我看一下

@shyser
Copy link
Author

shyser commented Jun 12, 2017

@ngot 好的,代码仓库已经建好,README里也有简要说明。
现在我已经在我的项目代码里去掉了sticky,用egg-socket.io往web推送消息目前没发现问题。而这个项目之前运行在在node 7.x 下,如果不添加sticky确实是不行的。

@ngot
Copy link
Member

ngot commented Jun 13, 2017

@StephenSeraph 我本地用node8 clone你的代码,未出现任何错误,能提供更具体一些嗯报错信息吗?

@shyser
Copy link
Author

shyser commented Jun 13, 2017

  • @ngot 我也重新clone了一遍,把完整的从 git clone 一直到报错的记录都上传到了 error.log,比较长,所以放在了示例项目里。
  • clone之后没做任何的改动,安装模块,启动程序,然后浏览器访问http://127.0.0.1:7001, 5秒钟之后报错了。

@ngot
Copy link
Member

ngot commented Jun 14, 2017

我换Ubuntu试试

@shyser
Copy link
Author

shyser commented Jun 14, 2017

@ngot 我也怀疑可能是我电脑环境或者操作系统的问题,昨天下班回去在我家里的Windows上走了一遍,也报错了。你是不是没有访问http://127.0.0.1:7001

@ngot
Copy link
Member

ngot commented Jun 14, 2017

依然未复现:

zhf@ubuntu:~/Documents/test/s/egg-socket-io-test$ arch
x86_64
zhf@ubuntu:~/Documents/test/s/egg-socket-io-test$ uname
Linux
zhf@ubuntu:~/Documents/test/s/egg-socket-io-test$ node -v
v8.1.1
zhf@ubuntu:~/Documents/test/s/egg-socket-io-test$ cnpm -v
cnpm@5.0.0 (/home/zhf/.nvm/versions/node/v8.1.1/lib/node_modules/cnpm/lib/parse_argv.js)
npm@5.0.3 (/home/zhf/.nvm/versions/node/v8.1.1/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@8.1.1 (/home/zhf/.nvm/versions/node/v8.1.1/bin/node)
npminstall@3.0.1 (/home/zhf/.nvm/versions/node/v8.1.1/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/home/zhf/.nvm/versions/node/v8.1.1 
linux x64 4.4.0-72-generic 
registry=http://registry.npm.taobao.org

@ngot
Copy link
Member

ngot commented Jun 14, 2017

浏览器访问 http://127.0.0.1:7001 无限等待访问,无更多日志

zhf@ubuntu:~/Documents/test/s/egg-socket-io-test$ cnpm run dev

> socket-io-test@1.0.0 dev /home/zhf/Documents/test/s/egg-socket-io-test
> egg-bin dev

2017-06-14 00:32:48,056 INFO 4180 [master] egg version 1.4.0
2017-06-14 00:32:48,402 INFO 4180 [master] agent_worker#1:4186 started (341ms)
2017-06-14 00:32:49,032 INFO 4180 [master] egg started on http://127.0.0.1:7001 (974ms)


@shyser
Copy link
Author

shyser commented Jun 14, 2017

嗯,我注意到了,cnpm run dev确实没报,但是用npm start 或者env EGG_SERVER_ENV=prod npm start报了。
我再琢磨琢磨,非常感谢你的耐心支持!

@shyser
Copy link
Author

shyser commented Jun 15, 2017

@ngot npm start报错的原因能帮我解释一下吗?是属于bug性质的,还是我的用法问题啊?

@ngot
Copy link
Member

ngot commented Jun 21, 2017

npm start 我也没报错。

@shyser
Copy link
Author

shyser commented Jun 23, 2017

这个,好尴尬呀……
然后我在Docker里跑了一下测试项目,当用浏览器访问时也报了
这是docker-compose文件

version: '3'
services:
  egg-test:
    container_name: egg-test
    image: hub.c.163.com/library/node:8.0.0-alpine
    volumes:
      - ./egg-socket-io-test:/usr/src/app
    ports:
      - 7004:7001
    working_dir: /usr/src/app
    command: npm start

如果你那边一直都不能复现,要不就先把这个issue关掉吧,尴尬……

@shyser
Copy link
Author

shyser commented Jun 23, 2017

刚才去docker仓库逛了一圈,163家的仓库似乎把node 8.0.0撤掉了,然后我升级为最新的8.1.2,居然不报错了!
然后把镜像源切换到官方,一一跑一遍,8.0.0、8.1.0会报错,往后的8.1.1和8.1.2没再报错了。

@shyser
Copy link
Author

shyser commented Jun 23, 2017

@ngot 然后我扫了一遍8.1.1的更新日志,发现有这么一条:fff8a56d6f - http: handle cases where socket.server is null (Luigi Pinca) #13578 #13435,应该就是它了!

@ngot
Copy link
Member

ngot commented Jun 23, 2017

尴尬了

@popomore
Copy link
Member

可以用 nodeinstall

@ngot
Copy link
Member

ngot commented Jun 27, 2017

结论是node的bug.

@ngot ngot closed this as completed Jun 27, 2017
@thonatos
Copy link
Member

thonatos commented Oct 18, 2017

➔ node -v
v8.0.0

我这边也是,稍后升级一下试试

还真是 node 版本问题,升级 8.6.0 以后就好了
建议备注一下到文档里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants