mail: IMAP inbound protocol destructor fix
This should fix crashes of mailer_daemon in IMAP workers. This patch makes IMAPConnection destructor wait for all working threads to finish. Also, do not call _Connect for QuitCommand (it speedups shutdown procedure). Change-Id: Idffcc00d3459a96a85a8a073a343bcf4cd4984be Reviewed-on: https://review.haiku-os.org/686 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
71103e733c
commit
1f41c99ffa
@ -618,6 +618,10 @@ void
|
||||
IMAPConnectionWorker::Quit()
|
||||
{
|
||||
printf("IMAP: worker %p: enqueue quit\n", this);
|
||||
BAutolock locker(fLocker);
|
||||
while (!fPendingCommands.IsEmpty())
|
||||
delete(fPendingCommands.RemoveItemAt(0));
|
||||
locker.Unlock();
|
||||
_EnqueueCommand(new QuitCommand());
|
||||
}
|
||||
|
||||
@ -732,7 +736,11 @@ IMAPConnectionWorker::_Worker()
|
||||
|
||||
CommandDeleter deleter(*this, command);
|
||||
|
||||
status_t status = _Connect();
|
||||
status_t status = B_OK;
|
||||
|
||||
if (dynamic_cast<QuitCommand*>(command) == NULL) // do not connect on QuitCommand
|
||||
status = _Connect();
|
||||
|
||||
if (status != B_OK) {
|
||||
fOwner.WorkerQuit(this);
|
||||
return status;
|
||||
|
@ -38,6 +38,15 @@ IMAPProtocol::IMAPProtocol(const BMailAccountSettings& settings)
|
||||
|
||||
IMAPProtocol::~IMAPProtocol()
|
||||
{
|
||||
MutexLocker locker(fWorkerLock);
|
||||
for (int32 i = 0; i < fWorkers.CountItems(); i++)
|
||||
fWorkers.ItemAt(i)->Quit();
|
||||
int tries = 10;
|
||||
while (fWorkers.CountItems() > 0 && --tries > 0) {
|
||||
locker.Unlock();
|
||||
snooze(500000);
|
||||
locker.Lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user