@mikro-orm/postgresql 7.2.6-dev.11 → 7.2.6-dev.13

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.
@@ -15,8 +15,9 @@ export declare class PostgreSqlConnection extends AbstractSqlConnection {
15
15
  * Both of the paths that emit one are unguarded by default: `pg-pool` removes its own listener
16
16
  * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
17
17
  * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
18
- * its own, so there is nothing to do here beyond logging — the pool has already discarded the
19
- * broken client by the time we see it.
18
+ * its own. An idle client is already discarded by the pool by the time we see it, a checked-out one
19
+ * is released here, as kysely's `ControlledTransaction` only releases after a successful
20
+ * commit/rollback (kysely-org/kysely#1990), which a dead connection never gets.
20
21
  */
21
22
  private handlePoolErrors;
22
23
  /** Applies the active EM's session context (or resets it) on every pooled connection acquire. */
@@ -35,12 +35,24 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
35
35
  * Both of the paths that emit one are unguarded by default: `pg-pool` removes its own listener
36
36
  * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
37
37
  * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
38
- * its own, so there is nothing to do here beyond logging — the pool has already discarded the
39
- * broken client by the time we see it.
38
+ * its own. An idle client is already discarded by the pool by the time we see it, a checked-out one
39
+ * is released here, as kysely's `ControlledTransaction` only releases after a successful
40
+ * commit/rollback (kysely-org/kysely#1990), which a dead connection never gets.
40
41
  */
41
42
  handlePoolErrors(pool) {
43
+ const checkedOut = new WeakSet();
44
+ pool.on('acquire', client => checkedOut.add(client));
45
+ pool.on('release', (_err, client) => checkedOut.delete(client));
42
46
  pool.on('connect', client => {
43
- client.on('error', e => this.logger.warn('info', `PostgreSQL connection error: ${e.message}`));
47
+ client.on('error', e => {
48
+ this.logger.warn('info', `PostgreSQL connection error: ${e.message}`);
49
+ // kysely still releases a client whose plain query failed, and `pg-pool` throws on a second release
50
+ if (checkedOut.has(client)) {
51
+ const release = client.release;
52
+ client.release = () => undefined;
53
+ release(e);
54
+ }
55
+ });
44
56
  });
45
57
  pool.on('error', e => this.logger.warn('info', `PostgreSQL pool error: ${e.message}`));
46
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "7.2.6-dev.11",
3
+ "version": "7.2.6-dev.13",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -47,7 +47,7 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.2.6-dev.11",
50
+ "@mikro-orm/sql": "7.2.6-dev.13",
51
51
  "kysely": "0.29.6",
52
52
  "pg": "8.23.1",
53
53
  "pg-cursor": "2.22.1",
@@ -59,7 +59,7 @@
59
59
  "@mikro-orm/core": "^7.2.5"
60
60
  },
61
61
  "peerDependencies": {
62
- "@mikro-orm/core": "7.2.6-dev.11"
62
+ "@mikro-orm/core": "7.2.6-dev.13"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">= 22.17.0"