http-agent icon indicating copy to clipboard operation
http-agent copied to clipboard

Race condition when using addUrl

Open tttp opened this issue 13 years ago • 0 comments

Hi,

The event stop is sent even so all the pages aren't nexed. It's probably something related of me addUrl(s) in the nextEvent.

For what I saw (ie. might be way off), the issue is that

HttpAgent.prototype.next = function (url) { if (this._running) { // If the URL passed in exists, remove it // from our _unvisited collection var index = this._unvisited.indexOf(url); if (index !== -1) { this._unvisited = this._unvisited.splice(index, 1);
} var shouldVisit = url || this._unvisited.length > 0;

// TODO: Be more robust than just 'GET'
if (shouldVisit) {
  this.url = url || this._unvisited.shift();
  this._makeRequest(this.url);
}
else {
  this.stop();
}

} }

if the last url to visit calls addUrl on the next (called by makeRequest), the stop event has already been sent.

Not quite sure how to deal with it in a clean way (not even that sure that's the issue).

I will try to add a new 'next' event listener and try to manipulate the unvisited from there. Any idea more than welcome.

tttp avatar Jan 22 '12 23:01 tttp