【bug反馈】pomelo 2.2.5 使用sioconnector报错,已经替官方找到原因了,求改正

运行node app 报错:

[2017-04-20 09:45:47.089] [INFO] pomelo-admin - 83: [ConsoleService] try to connect master: "gate", "127.0.0.1", 3005
[2017-04-20 09:45:47.281] [INFO] pomelo - 377: [/root/WebstormProjects/treasures/game-server/node_modules/pomelo/lib/application.js] "gate-server-1" enter after start...
[2017-04-20 09:45:47.368] [ERROR] console - Option path is not valid. Please refer to the README.
[2017-04-20 09:45:47.368] [ERROR] console - Option close timeout is not valid. Please refer to the README.
[2017-04-20 09:45:47.369] [ERROR] console - Option heartbeats is not valid. Please refer to the README.
[2017-04-20 09:45:47.369] [ERROR] console - Option log level is not valid. Please refer to the README.
[2017-04-20 09:45:47.369] [INFO] console - sio Server listening at port 3015
[2017-04-20 09:45:47.369] [INFO] pomelo - 409: [/root/WebstormProjects/treasures/game-server/node_modules/pomelo/lib/application.js] "gate-server-1" finish start

============================================
使用socket.io-client连接后 game-server端报错:

[2017-04-20 10:30:31.338] [ERROR] console - Caught exception: TypeError: Cannot read property 'indexOf' of undefined
    at Server.verify (/root/WebstormProjects/treasures/game-server/node_modules/engine.io/lib/server.js:132:24)
    at Server.handleRequest (/root/WebstormProjects/treasures/game-server/node_modules/engine.io/lib/server.js:205:8)
    at Server.<anonymous> (/root/WebstormProjects/treasures/game-server/node_modules/engine.io/lib/server.js:432:12)
    at Server.<anonymous> (/root/WebstormProjects/treasures/game-server/node_modules/socket.io/lib/index.js:275:16)
    at emitTwo (events.js:106:13)
    at Server.emit (events.js:192:7)
    at parserOnIncoming (_http_server.js:565:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)

错误在于两点:
1 pomelo2.2.5以后 @fantasyni 又提交了commit修正了sioconnector错误,如下,但没有提交到npm包里
,于是导致了前半段错误
https://github.com/NetEase/pomelo/commit/c808640c443fe50e214c55d52d05f28f92ff102d
2 这个commit修正并不成功,this.opts.transports还是没有设置,是undefined

着急的可以像我这么修改,npm install pomelo后,进入node_modules的pomelo中,先按照@fantasyni 的commit的改掉,然后进入lib/connectors/sioConnector.js中,把原来的:

if(this.opts) {
    opts = this.opts;
  } else {
    opts = {
      transports: [
      'websocket', 'polling-xhr', 'polling-jsonp', 'polling'
      ]
    };
  }

改成这么写:

if(this.opts) {
    opts = this.opts;
  }
  if(!this.opts.transports) {
      opts.transports = [
          'websocket', 'polling-xhr', 'polling-jsonp', 'polling'
      ];
  }

这样就能够正常使用sioconnector
我估计网易大神没想到空对象{}也是返回true的,导致一直走if语句,不走else语句

标签: bug 反馈
MissLee 在 4-20 11:45发布
MissLee 在 4-21 10:35重新编辑 分享到 weibo
6 回复
#1 {1} xymeng 4-21 01:19 回复

pomelo 2.2.5 是不是不支持sioconnector了

MissLee 4-21 10:35 回复

加油挣钱娶老婆

#2 {1} MissLee 20 小时前 回复

sioconnector的wss协议也有问题。。。唉。。。真是醉了

MissLee 18 小时前 回复

找到原因了,hybridconnector中有下面这样的代码,所以支持ws和wss

if(!this.ssl) {
    this.listeningServer = net.createServer();
  } else {
    this.listeningServer = tls.createServer(this.ssl);
  }

而sioconnector没有对应的选择用http或https来createServer的代码。
很简单的bug,有空提pr

#3 MissLee 18 小时前 回复

提多少个pr能进贡献者名单啊,我看nextzeus大神都没进

#4 MissLee 17 小时前 回复

sioconnector的stop函数也有bug,不知道意图是什么,没法改

/**
 * Stop connector
 */
Connector.prototype.stop = function(force, cb) {
  this.wsocket.server.close();
  process.nextTick(cb);
};
#5 MissLee 17 小时前 回复

sioconnector改成了class,结果pomelo不是通过new来调用的。。。。

#6 MissLee 17 小时前 回复

wss搞定了,哭了要

回到顶部