Fixed assertion error if --retry-wait is used

In CreateRequestCommand, if Request object returned from getRequest()
is still sleeping, CreateRequestCommand pools it back but still holds
its reference. This makes assertion error in
UnknownLengthPieceStroage::hasMissingUnusedPiece() from
AbstractCommand::execute().
pull/28/head
Tatsuhiro Tsujikawa 2012-08-31 22:31:31 +09:00
parent d59300d582
commit 0bbda43385
3 changed files with 13 additions and 0 deletions

View File

@ -896,6 +896,11 @@ void AbstractCommand::setRequest(const SharedHandle<Request>& request)
req_ = request;
}
void AbstractCommand::resetRequest()
{
req_.reset();
}
void AbstractCommand::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
{
fileEntry_ = fileEntry;

View File

@ -110,6 +110,10 @@ protected:
void setRequest(const SharedHandle<Request>& request);
// Resets request_. This method is more efficient than
// setRequest(SharedHandle<Request>());
void resetRequest();
const SharedHandle<FileEntry>& getFileEntry() const
{
return fileEntry_;

View File

@ -101,6 +101,10 @@ bool CreateRequestCommand::executeInternal()
} else if(getRequest()->getWakeTime() > global::wallclock()) {
A2_LOG_DEBUG("This request object is still sleeping.");
getFileEntry()->poolRequest(getRequest());
// Reset request of this command. Without this, request is doubly
// counted (1 for pooled and another one in this command) and
// AbstractCommand::execute() will behave badly.
resetRequest();
getDownloadEngine()->addCommand(this);
return false;
}