From c04a4167250bfa236f78e91352867aa3c6c9c33f Mon Sep 17 00:00:00 2001 From: David Chevers Williams Date: Sat, 29 Jul 2017 22:51:49 +1000 Subject: [PATCH] Raise error when streaming from a removed torrent In Node.js 8.2.1, when a torrent is removed while a file from it is being streamed, file-stream.js exits, crashing Node with a TypeError: VM535 file-stream.js:64 Uncaught TypeError: Cannot read property 'get' of null This patch checks whether the torrent has been marked as destroyed, and if so, raises the error to the file stream. --- lib/file-stream.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/file-stream.js b/lib/file-stream.js index 508f3584..11514b48 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -56,6 +56,8 @@ FileStream.prototype._notify = function () { if (self._notifying) return self._notifying = true + if (self._torrent.destroyed) return self._destroy(new Error('Torrent removed')) + var p = self._piece self._torrent.store.get(p, function (err, buffer) { self._notifying = false