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

[pinus-admin] pinus-admin客户端connect问题。 #668

Closed
TayeShi opened this issue Apr 12, 2023 · 2 comments
Closed

[pinus-admin] pinus-admin客户端connect问题。 #668

TayeShi opened this issue Apr 12, 2023 · 2 comments

Comments

@TayeShi
Copy link

TayeShi commented Apr 12, 2023

问题如下:

通过pinus-admin可以连接到游戏服。比如pinus-admin-web通过pinus-admin监控服务状态。
所以我也在gm web工具端,用了pinus-admin连接到游戏服,处理一些gm指令。
由于是长链接,对客户端的connect做了缓存处理,保持复用。
但是游戏服可能会关闭重启,gm web工具不需要重启。gm web工具server端使用的eggjs开发,通过pinus-admin连接游戏服。
但使用中存在异常情况:
当游戏服未启动时,通过gm工具发送指令,会导致gm web工具server端异常关闭退出。

代码分析:
在mqttConnect时,有个监听error

connect(host ?: string, port ?: number, cb ?: Function) {
        cb = cb || function () { };
        if (this.connected) {
            return cb(new Error('MqttClient has already connected.'));
        }

        if (host) {
            this.host = host;
        } else {
            host = this.host;
        }

        if (port) {
            this.port = port;
        } else {
            port = this.port;
        }

        let self = this;
        this.closed = false;

        let stream = net.createConnection(this.port, this.host);
        this.socket = MqttCon(stream);

        // logger.info('try to connect %s %s', this.host, this.port);
        this.socket.connect({
            clientId: this.clientId
        });

...
this.socket.on('disconnect', () => {
      logger.error('mqtt socket is disconnect, remote server host: %s, port: %s', host, port);
      self.emit('disconnect', self.id);
      self.onSocketClose();
    });
...

有error事件

this.socket.on('error', () => {
      logger.error('mqtt socket is error, remote server host: %s, port: %s', host, port);
      self.onSocketClose();
    });

onSocketClose()中执行process.exit(0)

// 有exit
exit() {
logger.info('exit ...');
process.exit(0);
}


process.exit(0)会导致eggjs work退出
想问一下这里,如果超时,直接让mqttClient不连接就可以了。为什么要直接退出整个进程?设计目的是怎样情况

复现:
在未启动游戏服务的情况下,通过pinus-admin调用指令
@whtiehack
Copy link
Member

为啥会退出还真不知道.是pomelo的代码
https://github.com/NetEase/pomelo-admin/blob/03d31b87cd2e0b766b49a31032f873890ebcf86b/lib/protocol/mqtt/mqttClient.js#L226-L231

你可以自己改掉这个exit

import {MqttClient} from 'pinus-admin/lib/protocol/mqtt/mqttClient';

MqttClient['exit'] = function () {
    console.info("!!~~ mqtt client exit")
}

@TayeShi
Copy link
Author

TayeShi commented Apr 21, 2023

差不多也是这么处理的

@TayeShi TayeShi closed this as completed Apr 21, 2023
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

2 participants