Flush queues before shutdown