Skip to content

Commit

Permalink
destroy cancels ready. fixes #198
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Oct 19, 2019
1 parent ade9a4e commit 68504af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -545,6 +545,7 @@ var torrentStream = function (link, opts, cb) {
}

var onready = function () {
if (destroyed) return
swarm.on('wire', onwire)
swarm.wires.forEach(onwire)

Expand Down
20 changes: 20 additions & 0 deletions test/tracker.js
Expand Up @@ -113,3 +113,23 @@ test('cleanup', function (t) {
fixture.destroy(t.ok.bind(t, true, 'should be destroyed'))
server.close(t.ok.bind(t, true, 'tracker should be closed'))
})

test('calling destroy() before \'ready\' should not hold event loop open', function (t) {
t.plan(4)
var engine = null
var server = new tracker.Server()
server.once('listening', function () {
t.ok(true, 'tracker should be listening')

engine = torrents(torrent, { dht: false, trackers: ['http://127.0.0.1:54321/announce'] })
engine.destroy(function () {
engine.remove(t.ok.bind(t, true, 'should be destroyed'))
})
})
server.once('start', function (addr) {
t.equal(addr, '127.0.0.1:6881')

server.close(t.ok.bind(t, true, 'tracker should be closed'))
})
server.listen(54321)
})

0 comments on commit 68504af

Please sign in to comment.