@torrent-tv/proxy 2.9.41 → 2.9.42
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 +5 -0
- package/package.json +2 -2
- package/services/torrent-pool.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## 2.9.42
|
|
2
|
+
|
|
3
|
+
- **Fix**: Torrents failed to load with a proxy crash — the REAL root cause (2.9.41 misdiagnosed it). WebTorrent 2.8.5's `Torrent._onTorrentId` does `arr2hex(parsedTorrent.infoHash)`, but `parse-torrent` returns `infoHash` as a hex **string**. `uint8-util` **2.3.x** rewrote `arr2hex` to require a TypedArray (`Buffer.from(data.buffer …)`); a string's `.buffer` is `undefined` → `Buffer.from(undefined)` → `ERR_INVALID_ARG_TYPE` thrown in a detached microtask. `uint8-util` 2.2.x iterated the argument and tolerated a string, so it only broke once the addon's unpinned global `npm install` pulled 2.3.x. It hit **every** torrent (v1/v2/hybrid alike — `arr2hex` is always called). Diagnosed by reproducing `client.add` inside the addon container and isolating `arr2hex('<hex>')` throwing on 2.3.2 but not 2.2.6. Fix: update **WebTorrent 2.8.5 → 3.x**, where the maintainer replaced that line with `parsedTorrent.infoHash?.substring(0, 7)` (no `arr2hex` on the string) — a proper dependency-forward fix, not a version pin, so `uint8-util`/`parse-torrent` stay current. Verified: the exact broken combo (webtorrent 3.0.16 + uint8-util 2.3.2 + parse-torrent 11.0.23) now adds cleanly, and the full API the proxy uses (`select`/`deselect`/`critical`/`_critical`/`wires`/`throttleUpload`/`createReadStream`/`destroy({destroyStore})`) is unchanged in 3.x.
|
|
4
|
+
- **Fix**: Removed the 2.9.41 infohash pre-validation. It was based on the wrong diagnosis ("v2-only torrent") — the failing torrents were normal v1 — and it wrongly rejected legitimate v2/hybrid sources. WebTorrent (post-bump) handles v1, v2 and hybrid itself. The last-resort `uncaughtException`/`unhandledRejection` guard from 2.9.41 is kept as defense-in-depth.
|
|
5
|
+
|
|
1
6
|
## 2.9.41
|
|
2
7
|
|
|
3
8
|
- **Fix**: A malformed or v2-only torrent source no longer crashes the whole proxy in a restart loop. WebTorrent's `Torrent._onTorrentId` does `arr2hex(parsedTorrent.infoHash)` assuming a BitTorrent v1 infohash exists; a v2-only / hybrid magnet (or a corrupt source) parses with `infoHash === undefined`, so that becomes `Buffer.from(undefined)` and throws in a microtask that bypasses the client `error` event — taking down the node and every viewer on it (observed: `ERR_INVALID_ARG_TYPE` → tunnel reconnect loop; the WebRTC session died ~6 s in as the process restarted under it). Two fixes: the torrent-add path now **pre-validates the infohash** with `parse-torrent` and rejects a source without a valid v1 40-hex infohash as a clean error the browser can show; and the process gained a **last-resort `uncaughtException`/`unhandledRejection` guard** that logs the full stack and keeps serving, so no single bad torrent can ever crash-loop the proxy. NOT a regression from the download-performance work (2.9.40) — those paths don't touch torrent parsing; it is a pre-existing crash surfaced by an unusual source.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torrent-tv/proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.42",
|
|
4
4
|
"description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"franc": "^6.2.0",
|
|
30
30
|
"get-port": "^7.1.0",
|
|
31
31
|
"node-datachannel": "^0.32.0",
|
|
32
|
-
"webtorrent": "^
|
|
32
|
+
"webtorrent": "^3.0.16",
|
|
33
33
|
"ws": "^8.18.2"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/services/torrent-pool.js
CHANGED
|
@@ -11,7 +11,6 @@ import os from "node:os";
|
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import { rmSync, statfsSync } from "node:fs";
|
|
13
13
|
import WebTorrent from "webtorrent";
|
|
14
|
-
import parseTorrent from "parse-torrent";
|
|
15
14
|
import { logger } from "../utils/logger.js";
|
|
16
15
|
|
|
17
16
|
// WebTorrent's default download root (see webtorrent lib/torrent.js: TMP =
|
|
@@ -428,25 +427,6 @@ export class TorrentPool {
|
|
|
428
427
|
|
|
429
428
|
const torrentId = decodeTorrentSource(sourceType, source);
|
|
430
429
|
|
|
431
|
-
// Pre-validate the infohash BEFORE handing the source to WebTorrent.
|
|
432
|
-
// WebTorrent's Torrent._onTorrentId does `arr2hex(parsedTorrent.infoHash)`
|
|
433
|
-
// assuming a BitTorrent v1 infohash exists; a v2-only / hybrid magnet (or a
|
|
434
|
-
// malformed source) parses with `infoHash === undefined`, so that call does
|
|
435
|
-
// `Buffer.from(undefined)` and throws in a microtask that bypasses the
|
|
436
|
-
// client "error" event — crashing the whole process. Reject cleanly here so
|
|
437
|
-
// the browser gets an error it can show, and the proxy stays up.
|
|
438
|
-
let parsed;
|
|
439
|
-
try {
|
|
440
|
-
parsed = await parseTorrent(torrentId);
|
|
441
|
-
} catch {
|
|
442
|
-
parsed = null;
|
|
443
|
-
}
|
|
444
|
-
if (!parsed || typeof parsed.infoHash !== "string" || !/^[0-9a-f]{40}$/i.test(parsed.infoHash)) {
|
|
445
|
-
throw new Error(
|
|
446
|
-
"Unsupported torrent source: no BitTorrent v1 infohash (v2-only or malformed torrents are not supported)."
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
430
|
const promise = new Promise((resolve, reject) => {
|
|
451
431
|
const onError = (error) => {
|
|
452
432
|
this.client.off("error", onError);
|