Closes #3439 (closed). Fixes a bug that could cause batched streams to be closed early.
Changelog: fix