简体   繁体   English

来自node.js websocket服务器的间歇性500错误

[英]intermittent 500 error coming from node.js websocket server

I have a websocket node.js app (game server) that runs a multiplayer html5 game. 我有一个websocket node.js应用程序(游戏服务器)运行多人html5游戏。

The game has a website also. 游戏也有一个网站。 The game server and the website are on the same Apache VPS. 游戏服务器和网站在同一个Apache VPS上。

The game server uses mysql to store and retrieve data using mysql pooling from the node.js mysql package. 游戏服务器使用mysql来存储和检索来自node.js mysql包的mysql池的数据。

It works fine 99% of the time, but intermittently, at a random point, it will all of a sudden stop being able to get a mysql connection. 它在99%的时间内工作正常,但间歇性地,在一个随机点,它将突然停止能够获得mysql连接。

When this happens the website stops working and shows a 500 http error. 发生这种情况时,网站停止工作并显示500 http错误。 I believe that this is whats causing the problem in the game server. 我相信这是造成游戏服务器问题的原因。 Because of the 500 http error, mysql can no longer be connected to and thus pool.getConnection no longer works in the game server. 由于500 http错误,mysql无法再连接,因此pool.getConnection不再适用于游戏服务器。

I find it strange that even though Apache is throwing up a 500 error, the game server can still be accessed successfully through a websocket as usual. 我觉得奇怪的是,即使Apache出现500错误,游戏服务器仍然可以像往常一样通过websocket成功访问。 The only thing that appears to have stopped working inside the game server is mysql. 唯一似乎停止在游戏服务器内工作的是mysql。 The game client connects to the game server via websocket and the functions work correctly, except for being able to connect to mysql. 游戏客户端通过websocket连接到游戏服务器,功能正常,除了能够连接到mysql。

If I ctrl+c the game server to stop the node.js app (game server) then the 500 error goes away. 如果我ctrl + c游戏服务器停止node.js应用程序(游戏服务器),那么500错误消失。 The website instantly serves up again, and then if I restarting the game server, mysql is now working again. 该网站立即再次服务,然后如果我重新启动游戏服务器,mysql现在再次工作。

Obviously something in the game server is causing this to happen. 显然,游戏服务器中的某些东西会导致这种情况发生。 So far i cannot find what it is. 到目前为止,我找不到它是什么。 I am stuck now, i've spent a full week trying everything i could think of to debug this. 我现在被困住了,我花了整整一周的时间尝试我能想到的一切来调试这个。

After running debug mode on mysql, im seeing this; 在mysql上运行调试模式后,我看到了这个;

<-- ErrorPacket
ErrorPacket {
fieldCount: 255,
errno: 1203,
sqlStateMarker: '#',
sqlState: '42000',
message: 'User (i've hidden this) already has more than 
\'max_user_connections\' 
active connections' }

But I have it set to 100000 connections. 但我已将其设置为100000个连接。 No way is there that many being used. 没有办法使用那么多。 Every time I finish with a connection I use connection.release() to put it back into the pool. 每次我完成连接后,我都会使用connection.release()将其放回池中。 What do I need to do to fix this? 我需要做些什么来解决这个问题?

Please, any suggestion you have to debug this is greatly appreciated! 请,任何建议你必须调试这是非常感谢!

Thanks in advance. 提前致谢。

here is the way i'm using mysql in the game server 这是我在游戏服务器中使用mysql的方式

const mysql = require('mysql');

const pool = mysql.createPool({
        connectionLimit : 100000,
        host     : '***********',
        user     : '***********',
        password : "'***********",
        database : '***********',
        debug    :  true
});


pool.getConnection(function(err,connection){

    if (err) {
        console.log(err);
        return false;
    }   

    connection.query("select * from aTable  ",function(err,rows){

        if(err) {
            console.log(err);
            connection.release();
            return false;

        }

        // dos stuff here

        connection.release();
    })

})

1 thing i am wondering, if there is an error in the top error catch block here -> 我想知道的一件事,如果顶部错误捕获块中有错误 - >

 pool.getConnection(function(err,connection){

        if (err) {
            console.log(err);
            return false;
        }

Then the connection is not released right? 然后连接没有发布吧? So that would keep a connection alive and this is whats causing the problem? 这样可以保持连接活动,这是什么导致问题? over time an error happens here and there, after a random amount of time, enough of these happen and that's what is causing it? 随着时间的推移,一个错误发生在这里和那里,经过一段随机的时间后,足够的这些发生了,这是什么导致它? it's like a build up of open connections??? 它就像一个开放连接的建立???

This was the mistake i was making; 这是我犯的错误;

pool.getConnection(function(err,connection){

    if (err) {
        console.log(err);
        return false;
    }   

    connection.query("select * from aTable  ",function(err,rows){

        if(err) {
            console.log(err);
            connection.release();
            return false;

        }

        if(somethingrelevant){

            // do stuff

            connection.release();

        }

    })

})

And that meant that if somethingrelevant didn't happen, then the connection would stay open. 这意味着如果没有相关的事情发生,那么连接将保持开放。 My pool would continue to open new connections but they weren't always being put back. 我的游泳池将继续打开新的连接,但并不总是被放回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM