Fix unbound local var error in retry logic