Drain queues where appropriate to avoid race conditions

We have a theory that these two places require checks to ensure the queue is
drained/processed before continuing, to avoid a potential race.

Signed-off-by: Ken Barber <ken@bob.sh>
Merge pull request #1104 from kbarber/maint/stable/drain-queues-to-avoid-races

Drain queues where appropriate to avoid race conditions