velocious 1.0.586 → 1.0.587

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.586",
6
+ "version": "1.0.587",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -233,6 +233,13 @@ export default class VelociousDatabaseDriversBase {
233
233
  this._schemaCache = new Map()
234
234
  }
235
235
 
236
+ /**
237
+ * Cleans driver-specific session state before this logical connection is reusable.
238
+ * Drivers whose physical sessions cannot be safely reset should dispose them here.
239
+ * @returns {Promise<void>} - Resolves when the next checkout cannot observe prior session state.
240
+ */
241
+ async cleanupSessionStateAfterCheckout() {}
242
+
236
243
  /**
237
244
  * Runs add foreign key.
238
245
  * @param {string} tableName - Table name.
@@ -65,11 +65,34 @@ export default class VelociousDatabaseDriversMysql extends Base{
65
65
  * @returns {Promise<void>} - Resolves when complete.
66
66
  */
67
67
  async _close() {
68
- await this.pool?.end()
68
+ const pool = this.pool
69
+
70
+ if (!pool) return
71
+
72
+ await new Promise((resolve, reject) => {
73
+ pool.end((error) => {
74
+ if (error) {
75
+ reject(error)
76
+ } else {
77
+ resolve(undefined)
78
+ }
79
+ })
80
+ })
69
81
  this.pool = undefined
70
82
  this.resetCurrentSessionTimeZone()
71
83
  }
72
84
 
85
+ /**
86
+ * Disposes the physical MySQL session after each logical pool checkout.
87
+ * MySQL exposes open-ended session state, so reconnecting is safer than trying
88
+ * to enumerate and reset variables, temporary tables, prepared statements,
89
+ * SQL modes, and other caller-controlled state.
90
+ * @returns {Promise<void>} - Resolves after the physical session is closed.
91
+ */
92
+ async cleanupSessionStateAfterCheckout() {
93
+ await this._close()
94
+ }
95
+
73
96
  /**
74
97
  * Runs set connection checkout name.
75
98
  * @param {string | undefined} name - Human-readable name for this active checkout.
@@ -150,6 +150,7 @@ export default class VelociousDatabasePoolAsyncTrackedMultiConnection extends Ba
150
150
  await this.rollbackLeftOpenTransaction(connection)
151
151
  await connection.releaseHeldAdvisoryLocks()
152
152
  await connection.clearConnectionCheckoutName()
153
+ await connection.cleanupSessionStateAfterCheckout()
153
154
  } catch (error) {
154
155
  await this.closeCheckedOutConnectionAfterCheckinFailure(connection, id, error)
155
156
  throw error