Fix closing a non-empty substream resulting in an incorrect stream state