@torrent-tv/proxy 2.107.71 → 2.107.73

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.107.71",
3
+ "version": "2.107.73",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -269,6 +269,24 @@ export class EncodeInputs {
269
269
  existing.to = to;
270
270
  if (existing.result?.kind === "result" && existing.result.to > to) existing.result.to = Math.max(existing.from, to);
271
271
  }
272
+ // AN INPUT HOLDS THE PIECE IT IS TAKEN FOR. A stretch prepared for the
273
+ // piece before ends there; handed out for the next piece, the run was built
274
+ // `from 188, to 187`, made nothing and its ending failed the output
275
+ // (field 2026-11-09, 52 of 1562 runs, torrent-tv/meta#341). It is released
276
+ // and prepared again at once: its revision is the current one, so no event
277
+ // would prepare it.
278
+ const held = existing?.result;
279
+ const reaches = Math.min(serves, existing?.to ?? serves);
280
+ if (held?.kind === "result" && Number.isInteger(held.to) && held.to < reaches) {
281
+ this.#log(`encode input #${existing.from}..#${existing.to} of ${addressOf(output)}: ` +
282
+ `the held stretch #${held.from}..#${held.to} does not reach #${reaches}, the piece it is now taken for; ` +
283
+ "prepared again");
284
+ existing.result = null;
285
+ existing.noted = undefined;
286
+ held.release?.();
287
+ this.#prepare(existing);
288
+ return null;
289
+ }
272
290
  if (existing?.result?.kind === "result") {
273
291
  this.#requests.delete(key);
274
292
  return existing.result;
@@ -583,15 +601,19 @@ export class EncodeInputs {
583
601
  let minimum = originalInputBytes(firstSources);
584
602
  const stretches = new Map([[from, { sources: firstSources, bytes: minimum }]]);
585
603
  const held = new Map();
604
+ // What the container answered for each end that did not state an original
605
+ // stretch: a resolution's own answer, or the error it threw.
606
+ const unresolved = new Map();
586
607
  const at = async end => {
587
608
  if (!stretches.has(end)) {
588
609
  // A longer stretch that cannot be stated is not one to copy; the
589
610
  // shorter one already stated still runs.
590
611
  const current = () => this.#requests.get(request.key) === request && !request.controller.signal.aborted;
591
612
  const resolved = await this.#resolveTimed(request.timing, output, from, end, current, request.controller.signal,
592
- this.#readPriority(request, from, end)).catch(() => null);
593
- stretches.set(end, resolved?.kind === "result" && resolved.sources?.every(source => source.input.original === true)
594
- ? { sources: resolved.sources, bytes: originalInputBytes(resolved.sources) } : null);
613
+ this.#readPriority(request, from, end)).catch(error => ({ kind: "error", error }));
614
+ const original = resolved?.kind === "result" && resolved.sources?.every(source => source.input.original === true);
615
+ stretches.set(end, original ? { sources: resolved.sources, bytes: originalInputBytes(resolved.sources) } : null);
616
+ if (!original) unresolved.set(end, resolved);
595
617
  }
596
618
  return stretches.get(end);
597
619
  };
@@ -613,7 +635,21 @@ export class EncodeInputs {
613
635
  let floor = from;
614
636
  if (serves > from) {
615
637
  const covering = await at(serves);
638
+ if (this.#requests.get(request.key) !== request) return undefined;
616
639
  if (covering) { floor = serves; minimum = covering.bytes; }
640
+ else {
641
+ // NEVER A STRETCH ENDING BELOW THE PIECE IT IS FOR. While the stretch
642
+ // through `serves` cannot be stated, the request waits as that
643
+ // resolution answered (`needs-bytes` names the bytes that wake it), and
644
+ // a terminal answer is its answer; `#from..#from` would start a run past
645
+ // its input (torrent-tv/meta#341).
646
+ const answer = unresolved.get(serves);
647
+ if (answer?.kind === "error") throw answer.error;
648
+ if (answer?.kind === "result" || !answer?.kind) {
649
+ throw new Error(`the stretch #${from}..#${serves} is not stated as an original input`);
650
+ }
651
+ return answer;
652
+ }
617
653
  }
618
654
  const longest = async (maxBytes, memory = false) => {
619
655
  let good = floor, bad = null, step = 1;
@@ -353,11 +353,17 @@ export class EncodeRuns {
353
353
  if (this.#host.encodeInputs?.failureOf(output)) return ENCODE_RUN_STATE.ENDED_FAILED;
354
354
  if (output && this.liveRunsOf(output).length === 0 && this.#inputFailures.reason(output.outputKey)) return ENCODE_RUN_STATE.ENDED_FAILED;
355
355
  const state = output ? this.#host.encodeOrchestrator.stateOf(output.outputKey) : runStateOf([]);
356
- // A piece of a longer input failed and is to be made from an input holding
357
- // it alone: production has not ended, and a request for it is held rather
358
- // than refused (torrent-tv/meta#178).
359
- if (state === ENCODE_RUN_STATE.ENDED_FAILED && this.liveRunsOf(output).length === 0 &&
360
- this.#inputFailures.retrying(output.outputKey)) return ENCODE_RUN_STATE.IDLE;
356
+ // PRODUCTION ENDS ONLY ON A TERMINAL INPUT FACT. `ENDED_FAILED` is the
357
+ // last run's state, not the output's: whether a piece will not be made is
358
+ // stated by `EncodeInputs.failureOf` and `InputFailures.reason`, asked
359
+ // above. Field 2026-11-09: the only run `#188..#187` ended `EXITED_SHORT`
360
+ // with neither, the plan was already starting the next run, and
361
+ // segment-00188 was answered 500 at 16:45:02.538 (torrent-tv/meta#341).
362
+ // Without an encode-input owner (tests only), a piece of a longer input
363
+ // that failed and is to be made from an input holding it alone keeps
364
+ // production going too (torrent-tv/meta#178).
365
+ if (state === ENCODE_RUN_STATE.ENDED_FAILED && output && this.liveRunsOf(output).length === 0 &&
366
+ (this.#host.encodeInputs || this.#inputFailures.retrying(output.outputKey))) return ENCODE_RUN_STATE.IDLE;
361
367
  return state;
362
368
  }
363
369
 
@@ -1559,6 +1565,13 @@ export class EncodeRuns {
1559
1565
  }
1560
1566
  }
1561
1567
  this.#host.encodeOrchestrator.noteEnded(ended);
1568
+ // The field line of a failed run that does not end production: the next
1569
+ // run makes its pieces, and requests for them are held (torrent-tv/meta#341).
1570
+ if (ended.run?.state === ENCODE_RUN_STATE.ENDED_FAILED && !this.hasFailed(session)) {
1571
+ this.#host.logger.info(`encode: run #${ended.from}..#${ended.to} of ${session.outputKey} ended ` +
1572
+ `${ENCODE_RUN_STATE.ENDED_FAILED} (${ended.because}); production goes on — no input failure ends it, ` +
1573
+ "so requests for its pieces stay held");
1574
+ }
1562
1575
  // What this admitted encode was seen to do, kept for the next time this
1563
1576
  // host prices the same mode (roadmap item 97, step 14). Whatever the
1564
1577
  // ending: a run that failed still ran at the speed it ran at, and the
@@ -82,7 +82,7 @@ export const ENCODE_RUN_STATE = Object.freeze({
82
82
  STOPPED: "STOPPED",
83
83
  /** Ran through the last segment of the file. Nothing is owed. */
84
84
  ENDED_COMPLETE: "ENDED_COMPLETE",
85
- /** Terminal for this target: requests are answered as failures. */
85
+ /** Terminal for this run. The output fails only on a terminal input fact (`docs/encode-run-state.md`). */
86
86
  ENDED_FAILED: "ENDED_FAILED"
87
87
  });
88
88
 
@@ -106,7 +106,7 @@ export const STATE_MEANING = Object.freeze({
106
106
  [ENCODE_RUN_STATE.RETRY_WAIT]: "The input went away; a restart is timed. Requests are held, not refused.",
107
107
  [ENCODE_RUN_STATE.STOPPED]: "Stopped on purpose with no replacement — a rung the viewer switched away from.",
108
108
  [ENCODE_RUN_STATE.ENDED_COMPLETE]: "Ran through the last segment of the file. Nothing is owed.",
109
- [ENCODE_RUN_STATE.ENDED_FAILED]: "Terminal for this target: requests are answered as failures."
109
+ [ENCODE_RUN_STATE.ENDED_FAILED]: "Terminal for this run. The output fails only on a terminal input fact (see below)."
110
110
  });
111
111
 
112
112
  /**