Fix sporadic hang.

The buffer wasn't being processed completely, which under the right conditions
could leave the writer and reader both waiting for a signal to continue.