more consistent way of acquiring locks during error handling