@torrent-tv/proxy 2.101.7 → 2.101.8

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.101.7",
3
+ "version": "2.101.8",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -45,6 +45,14 @@ export async function handleEncodeInputGet(req, reply, { inputOf, refused = () =
45
45
  refused({ token, fileIndex, start: range.start, runTag: input.runTag ?? null });
46
46
  return reply.code(503).send({ error: "Original input bytes are outside the admitted ranges." });
47
47
  }
48
+ // A deferred read may finish after FFmpeg closed the connection. No close
49
+ // event remains to release an answer acquired after that event.
50
+ if (reply.raw?.destroyed || req.raw?.aborted) {
51
+ held.stream?.destroy();
52
+ held.release?.();
53
+ return reply;
54
+ }
55
+ const body = held.stream ?? (held.chunks ? Readable.from(held.chunks, { objectMode: false }) : held.bytes);
48
56
  // What was handed to the system for this answer before its connection
49
57
  // closed, and whether all of it was: an answer runs to the end of its
50
58
  // admitted range and FFmpeg closes the connection once it has what it wants,
@@ -54,12 +62,18 @@ export async function handleEncodeInputGet(req, reply, { inputOf, refused = () =
54
62
  const socket = req.raw?.socket;
55
63
  const writtenBefore = socket?.bytesWritten ?? 0;
56
64
  reply.raw?.once?.("close", () => {
65
+ body?.destroy?.();
57
66
  held.release?.();
58
67
  input.noteAnswer?.({ fileIndex, start: range.start, end: held.end,
59
68
  written: Math.max(0, (socket?.bytesWritten ?? writtenBefore) - writtenBefore),
60
69
  handedOver: reply.raw?.writableFinished === true });
61
70
  });
62
- return reply.code(206).header("Content-Length", String(held.size ?? held.bytes.length))
63
- .header("Content-Range", `bytes ${range.start}-${held.end}/${length}`)
64
- .send(held.stream ?? (held.chunks ? Readable.from(held.chunks, { objectMode: false }) : held.bytes));
71
+ try {
72
+ return reply.code(206).header("Content-Length", String(held.size ?? held.bytes.length))
73
+ .header("Content-Range", `bytes ${range.start}-${held.end}/${length}`).send(body);
74
+ } catch (error) {
75
+ body?.destroy?.();
76
+ held.release?.();
77
+ throw error;
78
+ }
65
79
  }