Move giant failout loop to its own function

It's about time..

Change-Id: I27df01e3eefb2ea1ad2a7c05844eff7f63f6e9f7
Reviewed-on: http://review.couchbase.org/29782
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>