ensure records are returned to buffer on error