request "connector.entryHandler.enter" timeout. 求帮助!!!

运行环境:win7 32位 + pomelo 0.7.1 + nodejs 0.10.21
以chatofpomelo为基础,加上lord的chatService
entryHandler.js

var channelUtil = require('../../../util/channelUtil');
var utils = require('../../../util/utils');
var userDao = require('../../../dao/userDao');
var async = require('async');

module.exports = function(app) {
  return new Handler(app);
};

var Handler = function(app) {
  this.app = app;
};

var handler = Handler.prototype;

/**
 * 新的客户端进入服务器处理。绑定用户信息
 *
 * @param  {Object}   msg     request message
 * @param  {Object}   session current session object
 * @param  {Function} next    next step callback
 * @return {Void}
 */
handler.enter = function(msg, session, next) {
    console.log("=== 我的ID:" + this.app.get('serverId'));
    var self = this, usersMap = null, cUser = null, mySid = this.app.get('serverId');
    async.waterfall([
        function(cb){
            var sessionService = self.app.get('sessionService');
            //重复登录
            if(!!sessionService.getByUid(msg.uid)) {
                next(null, {code:500, error:true});
                return;
            }
            console.log("验证是否重复登录!");
            cb();
        }, /*function(cb){
            //踢用户下线
            self.app.get('sessionService').kick(msg.uid, cb);
        },*/ function(cb){
            console.log("获取用户对象!");
            userDao.getUserById(msg.uid, cb);
        }, function(user, cb){
            if(!user){
                console.log("获取用户对象出错!" + user);
                next(null, {code:500, error:true, msg:"获取用户对象出错!"});
                return;
            }
            cUser = user;
            var uid = user.uid + '*' + user.username;
            console.log("绑定用户!ID:" + user.uid + '*' + user.username);
            session.bind(uid);  //绑定用户
            session.set('username', user.username);
            session.on('closed', onUserLeave.bind(null, self.app));
            session.pushAll(cb);
        }, /*function(cb){
            console.log("用户加入全局频道!");
            //加入到全局频道
            self.app.rpc.chat.chatRemote.add(session, mySid, cUser.uid, cUser.username, channelUtil.getGlobalChannelName(), cb);
        },*/ function(cb){
            console.log("用户加入房间频道!");
            //加入到房间
            self.app.rpc.chat.chatRemote.add(session, mySid, cUser.uid, cUser.username, channelUtil.getRoomChannelName(msg.rid), cb);
        }, function(cb){
            console.log("获取房间内的用户!");
            //获取该房间内的用户
            usersMap = self.app.rpc.chat.chatRemote.getUsers(channelUtil.getRoomChannelName(msg.rid), true, cb);
        }
    ], function(err) {
        if(!!err) {
            console.log("过程出错!");
            next(err, {code:500, error:true, msg:err});
            return;
        }
        console.log("一切正常!");
        next(null, {code:200, error:false, users:usersMap});
    });
};
/**
 * 用户退出处理
 *
 * @param {Object} app current application
 * @param {Object} session current session object
 *
 */
var onUserLeave = function(app, session) {
    if(!session || !session.uid) {
        return;
    }
    var uid = session.uid.split("*")[0];
    console.log("### session.uid :" + session.uid + " ## uid:" + uid);
    app.rpc.chat.chatRemote.kick(session, uid, null);
};

控制台信息:

[2013-11-14 11:43:36.116] [INFO] console - ============== 登录 ============
====== 用户名:mxlhy ,密码:2010

[2013-11-14 11:43:36.196] [INFO] console - 用户登录成功!登录用户ID为:1

[2013-11-14 11:43:36.895] [INFO] console - 请求的用户:mxlhy

[2013-11-14 11:43:36.895] [INFO] console - 获取的连接器ID:connector-server-2

[2013-11-14 11:43:36.926] [INFO] console - === 我的ID:connector-server-2

[2013-11-14 11:43:36.927] [INFO] console - 验证是否重复登录!

[2013-11-14 11:43:36.927] [INFO] console - 获取用户对象!

[2013-11-14 11:43:36.987] [INFO] console - 绑定用户!ID:1*mxlhy

[2013-11-14 11:43:36.987] [INFO] console - 用户加入房间频道!

[2013-11-14 11:43:37.009] [INFO] console - == 参数 == sid:connector-server-2 == uid:1 == username
:mxlhy == channelName:room_12

[2013-11-14 11:43:37.009] [INFO] console - === 加入频道:room_12 ===
[2013-11-14 11:43:37.016] [INFO] console - 获取房间内的用户!

[2013-11-14 11:43:39.939] [WARN] pomelo - [F:\pomelo\ddz\game-server\node_modules\pomelo\lib\filters
\handler\timeout.js] request "connector.entryHandler.enter" timeout.

[2013-11-14 11:43:39.939] [ERROR] pomelo - [F:\pomelo\ddz\game-server\node_modules\pomelo\lib\filter
s\handler\serial.js] [serial filter] msg timeout, msg:{"uid":1,"username":"mxlhy","rid":"12","timest
amp":1384400616925,"__route__":"connector.entryHandler.enter"}

请问这是为什么啊?
如果我不获取房间内的用户,它就不会报错,弄了一上午了,找不到原因啊!

标签:无
mxlhy 在 2013-11-14 12:03发布 分享到 weibo
7 回复
#1 {3} mxlhy 2013-11-14 12:35 回复

我的chatService.js

var utils = require('../util/utils');

var ChatService = function(app) {
  this.app = app;
  this.uidMap = {};     //用户ID集合
  this.nameMap = {};    //用户名称集合
  this.channelMap = {}; //频道集合
};

module.exports = ChatService;

/**
 * 添加玩家进入频道
 *
 * @param {String} sid          连接器ID
 * @param {Number} uid          用户ID
 * @param {String} username     用户名称
 * @param {String} channelName  频道名称
 * @return {Object} JSON格式的相关信息
 */
ChatService.prototype.add = function(sid, uid, username, channelName) {
    console.log("== 参数 == sid:" + sid + " == uid:" + uid + " == username:" + username + " == channelName:" + channelName);
  //var sid = getSidByUid(username, this.app);
  if(!sid) {
      console.log("没有连接器!");
    return {code:3003, msg:"没有连接器!"};
  }
  if(checkDuplicate(this, uid, channelName)) {
    return {code:200, msg:"频道"+channelName+"已存在,且用户进入频道成功!"};
  }

  var channel = this.app.get('channelService').getChannel(channelName, true);
  if(!channel) {
    return {code:3001, msg:"频道创建失败!"};
  }
console.log("=== 加入频道:"+channelName+" ===");
  channel.add(uid, sid);
  addRecord(this, uid, username, sid, channelName);
  channel.pushMessage({route:'onAdd', uid:uid, username:username});
  return {code:200, msg:"频道"+channelName+"已创建,且用户进入频道成功!"};
};
andymac 2013-12-10 15:49 回复

你这问题解决了吗? 我也遇到了

mxlhy 2013-12-10 17:52 回复

@andymac
肯定是解决了啊,不过,都好久了哦,
我都不记得当时是什么原因了。。

andymac 2013-12-11 09:40 回复

@mxlhy 我找到原因了,我的是因为某处漏写了cb回调

#2 mxlhy 2013-11-14 12:38 回复

我的chatRemote.js

module.exports = function(app) {
    return new ChatRemote(app, app.get('chatService'));
};

var ChatRemote = function(app, chatService) {
    this.app = app;
    this.chatService = chatService;
};

/**
 * 添加用户到聊天频道
 *
 * @param {String} sid          连接器ID
 * @param {Number} uid          用户ID(唯一)
 * @param {String} username     用户名称
 * @param {String} channelName  频道名称
 * @param {Function} cb         callback function
 */
ChatRemote.prototype.add = function(sid, uid, username, channelName, cb) {
    var code = this.chatService.add(sid, uid, username, channelName);
    if(!!cb && typeof cb === 'function') cb(null, code);
};

/**
 * 用户离开聊天频道
 * @param {Number} uid          用户ID(唯一)
 * @param {String} channelName  频道名称
 * @param {Function} cb         callback function
 */
ChatRemote.prototype.leave = function(uid, channelName, cb){
    this.chatService.leave(uid, channelName);
    if(!!cb && typeof cb === 'function') cb();
};

/**
 * 将用户踢出聊天频道
 *
 * @param {Number} uid      用户ID(唯一)
 * @param {Function} cb     callback function
 */
ChatRemote.prototype.kick = function(uid, cb) {
    this.chatService.kick(uid);
    if(!!cb && typeof cb === 'function') cb();
};

/**
 * 从聊天频道获取用户
 * 获取一个频道内的全部用户
 * @param {String} channelName 频道名称
 * @param {boolean} flag 频道参数 true:没有则创建,false:不创建
 * @return {Array} users 频道的用户集合
 */
ChatRemote.prototype.getUsers = function(channelName, flag) {
    var users = this.chatService.getUsers(channelName, flag);
    return users;
};
#3 fantasyni 2013-11-14 14:04 回复

handler 超时了

app.filter(pomelo.timeout(TIME_OUT)); // 这里传入你希望的timeout时间即可

#4 {1} tellyounews 2014-5-28 22:48 回复

3秒后,客户端怎么捕获?

fantasyni 2014-5-29 09:15 回复

@tellyounews 客户端要自己timeout处理

#5 skyxing7 2016-1-22 18:27 回复

可以说说你是怎么解决的吗?

#6 skyxing7 2016-1-22 18:27 回复

我现在也遇到了这样的问题,很着急。

#7 921314 1-14 00:01 回复

generic-pool升级成3.0.1
要改lordofpomelo\game-server\app\dao\mysql\dao-pool.js
lordofpomelo\game-server\app\dao\mysql\mysql.js

回到顶部