Fix race condition when updating output buffers

Fixes #1689