Correctly drain ring buffer in IO
Fixes race condition in ring buffer impl