@nxtedition/nxt-undici 7.3.11 → 7.3.12

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.
@@ -268,9 +268,9 @@ export class SqliteCacheStore {
268
268
  try {
269
269
  const startTime = performance.now()
270
270
  for (let retryCount = 0; true; retryCount++) {
271
- this.#db.exec('BEGIN')
272
271
  let n = 0
273
272
  try {
273
+ this.#db.exec('BEGIN')
274
274
  while (n < this.#insertBatch.length) {
275
275
  const {
276
276
  url,
@@ -314,11 +314,22 @@ export class SqliteCacheStore {
314
314
  } catch (err) {
315
315
  // ROLLBACK is required: a failed statement leaves the connection with
316
316
  // an open transaction; without it the next BEGIN would throw.
317
- this.#db.exec('ROLLBACK')
317
+ // On SQLITE_FULL, SQLite automatically rolls back the transaction, so
318
+ // the explicit ROLLBACK may fail with "no transaction is active" — ignore it.
319
+ try {
320
+ this.#db.exec('ROLLBACK')
321
+ } catch {
322
+ // already rolled back automatically
323
+ // TODO (fix): Check that the error is what we expect (something like "no transaction is active")...
324
+ }
325
+
318
326
  if (err?.errcode === 13 /* SQLITE_FULL */ && retryCount < 3) {
319
327
  this.#evictQuery.run(256)
320
328
  } else {
321
- this.#insertBatch.splice(0, n)
329
+ // If BEGIN failed (n=0) clear the whole batch to avoid an infinite
330
+ // retry loop. If an INSERT/COMMIT failed, only clear the entries
331
+ // that were part of the attempted transaction.
332
+ this.#insertBatch.splice(0, n || this.#insertBatch.length)
322
333
  throw err
323
334
  }
324
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "7.3.11",
3
+ "version": "7.3.12",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",