ensure finish and flush called automatically on close if not already done explicitly.