correctly drain incoming stream