Fix a race condition in the flushing of commands that