cgserver 13.2.3 → 13.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -140,11 +140,18 @@ class MongoExt {
140
140
  this._mongocfg.options.dbName = this._mongocfg.database;
141
141
  this._connection = mongoose_2.default.createConnection("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
142
142
  this._connection = this._connection.useDb(this._mongocfg.database);
143
- this._connection.on("open", this.onOpen.bind(this));
143
+ this._connection.once("open", this.onOpen.bind(this));
144
144
  this._connection.on("close", this.onClose.bind(this));
145
145
  this._connection.on("connectionCreated", this.onConnect.bind(this));
146
146
  this._connection.on("connectionClosed", this.onDisconnect.bind(this));
147
147
  await this._connection.asPromise();
148
+ while (this._connection.readyState != mongoose_1.ConnectionStates.connected) {
149
+ if (this._connection.readyState != mongoose_1.ConnectionStates.connecting) {
150
+ Log_1.gLog.error("MongoDB connection is not ready, please check the connection settings. Current state: " + this._connection.readyState);
151
+ return false;
152
+ }
153
+ await Core_1.core.sleep(100);
154
+ }
148
155
  console.log("mongo connect success! db=" + this._connection.name);
149
156
  return true;
150
157
  }
@@ -155,7 +162,10 @@ class MongoExt {
155
162
  this._cur_connecting_count--;
156
163
  }
157
164
  close(force = false) {
158
- mongoose_2.default.connection.close(force);
165
+ if (!this._connection) {
166
+ return;
167
+ }
168
+ this._connection.close(force);
159
169
  }
160
170
  registerInitCb(cb) {
161
171
  this._init_cbs.push(cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "13.2.3",
3
+ "version": "13.2.4",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",