Mysql Socket.io命名空间在10次连接后停止工作

Mysql Socket.io命名空间在10次连接后停止工作,mysql,node.js,express,socket.io,ejs,Mysql,Node.js,Express,Socket.io,Ejs,我正在使用node.js、ejs、express、mysql和socket.io。 我的服务器如下所示(index.js): 客户: <!DOCTYPE html> <html> <head> <title><%= channel_name %></title> </head> <body> <div id="message"></div> </body>

我正在使用node.js、ejs、express、mysql和socket.io。 我的服务器如下所示(index.js):

客户:

<!DOCTYPE html>
<html>
<head>
    <title><%= channel_name %></title>
</head>
<body>
<div id="message"></div>
</body>
</html>
<script src="/js/lib/jquery/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
<script>
var socket = io(`/chat/<%= channel_name %>`);

socket.on('say hi', function(data){
    $('#message').append(`<div>${data}</div>`)
})
</script>

var socket=io(`/chat/`);
socket.on('say hi',函数(数据){
$('#message')。追加(`${data}`)
})
基本上,当我重新启动服务器并尝试时,例如:
/chat/uk
,它会显示在html页面上:
Hi from uk
但是,在重新启动页面10次后(第11次),浏览器继续加载,并在命令提示符上显示
GET/chat/uk--ms-->
,为什么会发生这种情况?

另外,这是使用名称空间的正确方法吗?我想创建多个频道(名称空间),用户将连接这些频道,然后进行1对1私人聊天(聊天室)

这就是当您不编写响应并允许应用挂起时系统的反应。

GET /chat/uk - - ms - -

“-”为空,表示没有响应代码、时间或大小。翻译后,您将看到响应的未知属性

您的代码没有响应,也没有生成错误代码,并且从未到达以下行:

    if(err) return console.log(err) //happens twice 


    return res.redirect('/chat')


    res.render('channel', {channel_name: rows[0].channel_name})
问题可能在这一行:

    connection.query('SELECT * FROM channel WHERE channel_name = ?', channel_name, (err, rows) => {
您从未关闭以前与数据库的连接。尝试添加

    connection.release();
在代码中的某个时刻,因为到mysql数据库的可用连接可能已经用完。要查看,您可以查看此处的说明 或者使用这些命令

pool.config.connectionLimit     // passed in max size of the pool
pool._freeConnections.length    // number of free connections awaiting use
pool._allConnections.length     // number of connections currently created, including ones in use
pool._acquiringConnections.length // number of connections in the process of being acquired

让我知道这是否有效,或者是否有后续问题。

啊,是的<代码>连接.释放()修复:)谢谢!!还有一个额外的问题,我走对了吗?是应该这样做,还是有其他(正确的)方法来创建一个具有多个频道的应用程序?因此,在我使用redis管理频道之前,当我这样做时,我并不确定,我需要回顾一下
pool.config.connectionLimit     // passed in max size of the pool
pool._freeConnections.length    // number of free connections awaiting use
pool._allConnections.length     // number of connections currently created, including ones in use
pool._acquiringConnections.length // number of connections in the process of being acquired