Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop bug #1786

Open
wants to merge 5 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

torrent._update performance improvement

Queue torrent updates once per second, as it is an expensive operation. Before, this would cause updates to happen nearly every tick.
  • Loading branch information
koush committed Jan 2, 2020
commit 09c644566f2088a4e7f875885f4e44a349c3b299
@@ -1171,14 +1171,23 @@ class Torrent extends EventEmitter {
* Heartbeat to update all peers and their requests.
*/
_update () {
if (this.destroyed) return

// update wires in random order for better request distribution
const ite = randomIterate(this.wires)
let wire
while ((wire = ite())) {
this._updateWireWrapper(wire)
if (this._updateScheduled) {
this._debug('_update already queued')
return
}

this._updateScheduled = true
setTimeout(() => {
this._updateScheduled = false
if (this.destroyed) return

// update wires in random order for better request distribution
const ite = randomIterate(this.wires)
let wire
while ((wire = ite())) {
this._updateWireWrapper(wire)
}
}, 1000)
}

_updateWireWrapper (wire) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.