@mastra/pg 1.20.1-alpha.2 → 1.20.1-alpha.3
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/CHANGELOG.md +13 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +33 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/factory-storage.d.ts +22 -0
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.20.1-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Stop a dropped Postgres connection from killing the process while a client is checked out. ([#21765](https://github.com/mastra-ai/mastra/pull/21765))
|
|
8
|
+
|
|
9
|
+
`PgFactoryStorage` attached an `error` listener to the pool, but pg only routes pool-level errors for _idle_ clients — it hands ownership of a client to the borrower for the duration of a checkout. A backend restart or network blip that landed on a client mid-transaction therefore reached an emitter with nothing listening, and Node escalated it to an uncaughtException that took the whole server down (`Connection terminated unexpectedly` at `pg/lib/client.js`), even though the idle siblings were logged and discarded cleanly.
|
|
10
|
+
|
|
11
|
+
Pools created by `PgFactoryStorage` now attach a listener once per physical connection as it is established, so a client stays covered while borrowed. While the client is idle the pool's own listener already reports the failure, so the extra listener stays quiet and a dropped connection is announced once, as the right thing. The pool still discards the failed connection and reconnects on the next checkout; the failure is now logged instead of fatal. Caller-supplied pools are left untouched, as before.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`6db7a5d`](https://github.com/mastra-ai/mastra/commit/6db7a5dd3dd2b6f7ef75dcd804fcffef5fa83963), [`0cdc5dc`](https://github.com/mastra-ai/mastra/commit/0cdc5dc69024957815da4f51acc4119eb4f447d7)]:
|
|
14
|
+
- @mastra/core@1.60.0-alpha.12
|
|
15
|
+
|
|
3
16
|
## 1.20.1-alpha.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -20774,6 +20774,38 @@ var PgFactoryStorageOps = class {
|
|
|
20774
20774
|
* Supports serializable app-table transactions for cross-replica invariant
|
|
20775
20775
|
* enforcement and `authDatabase()` exposing the shared pool.
|
|
20776
20776
|
*/
|
|
20777
|
+
/**
|
|
20778
|
+
* A pool-level `error` listener only covers *idle* clients: pg hands ownership
|
|
20779
|
+
* of a client to the borrower for the duration of a checkout and takes its own
|
|
20780
|
+
* listener off. So a backend restart or network blip that lands on a client
|
|
20781
|
+
* mid-transaction reaches an emitter with no listener, and Node escalates that
|
|
20782
|
+
* to an uncaughtException that kills the process — the pool handler logs the
|
|
20783
|
+
* idle siblings and the borrowed one still brings everything down.
|
|
20784
|
+
*
|
|
20785
|
+
* Attach a listener once per physical connection instead. `connect` fires when
|
|
20786
|
+
* the pool establishes a client, so the client stays covered for its whole life
|
|
20787
|
+
* and there is nothing to remove on release.
|
|
20788
|
+
*
|
|
20789
|
+
* That listener outlives the checkout, so it also sees the failures the pool is
|
|
20790
|
+
* already reporting through its own idle listener. Follow `acquire`/`release`
|
|
20791
|
+
* to tell the two apart and stay quiet while the client is idle — otherwise one
|
|
20792
|
+
* dropped connection is announced twice, the second time as the wrong thing.
|
|
20793
|
+
*
|
|
20794
|
+
* The pool still discards the failed connection; this only keeps the failure
|
|
20795
|
+
* reportable instead of fatal.
|
|
20796
|
+
*/
|
|
20797
|
+
function guardCheckedOutClientErrors(pool, warn = console.warn) {
|
|
20798
|
+
const borrowed = /* @__PURE__ */ new WeakSet();
|
|
20799
|
+
pool.on("connect", (client) => {
|
|
20800
|
+
borrowed.add(client);
|
|
20801
|
+
client.on("error", (err) => {
|
|
20802
|
+
if (!borrowed.has(client)) return;
|
|
20803
|
+
warn(`PgFactoryStorage: client error while checked out (the pool discards this connection): ${err instanceof Error ? err.message : String(err)}`);
|
|
20804
|
+
});
|
|
20805
|
+
});
|
|
20806
|
+
pool.on("acquire", (client) => borrowed.add(client));
|
|
20807
|
+
pool.on("release", (_err, client) => borrowed.delete(client));
|
|
20808
|
+
}
|
|
20777
20809
|
var PgFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
|
|
20778
20810
|
ops;
|
|
20779
20811
|
#pool;
|
|
@@ -20794,6 +20826,7 @@ var PgFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
|
|
|
20794
20826
|
this.#pool.on("error", (err) => {
|
|
20795
20827
|
console.warn(`PgFactoryStorage: idle pool client error (pool discards the client and reconnects on next checkout): ${err instanceof Error ? err.message : String(err)}`);
|
|
20796
20828
|
});
|
|
20829
|
+
guardCheckedOutClientErrors(this.#pool);
|
|
20797
20830
|
}
|
|
20798
20831
|
this.ops = new PgFactoryStorageOps(this.#pool, this.#schemas);
|
|
20799
20832
|
}
|