lsc 2 weeks ago
parent
commit
e16c4468bf
2 changed files with 15 additions and 5 deletions
  1. 8 3
      mongo.js
  2. 7 2
      mysql.js

+ 8 - 3
mongo.js

@@ -15,9 +15,14 @@ us.initMongoConnection = async function (host, database) {
         us.client = new us.mongo.MongoClient(url, {
             useNewUrlParser: true,
             useUnifiedTopology: true,
-            maxPoolSize: 10000, // 设置连接池没有上限
-            serverSelectionTimeoutMS: 5000, // 服务器选择超时
-            socketTimeoutMS: 45000 // 套接字超时
+            maxPoolSize: 50, // 降低连接池大小,避免资源耗尽
+            minPoolSize: 5,  // 设置最小连接数
+            maxIdleTimeMS: 30000, // 连接最大空闲时间
+            serverSelectionTimeoutMS: 5000,
+            socketTimeoutMS: 45000,
+            connectTimeoutMS: 10000, // 添加连接超时
+            keepAlive: true, // 保持连接活跃
+            keepAliveInitialDelay: 300000 // 保持连接初始延迟
         });
         try {
             await us.client.connect();

+ 7 - 2
mysql.js

@@ -43,8 +43,13 @@ exports.usselect = function (param, callback) {
                 callback(error);
             } else { //连接成功
                 for (i = 0; i < param.length; i++) {
-                    param[i] = decodeURIComponent(param[i]);
-
+                    try {
+                        param[i] = decodeURIComponent(param[i]);
+                    } catch(e) {
+                        // 解码失败可以选择日志记录或保留原值
+                        console.log(`decodeURIComponent error at index ${i}:`, param[i], e);
+                        // param[i] = param[i]; // 可省略,不做处理
+                    }
                 } //格式化处理参数
                 var i, _sql = "CALL ";
                 var _param = new Array();