Fixed the "defer" statement in Do() retry loop.

Encapsulated the code block that does the defer call within an anonymous
function. This way defer statement works properly and returns every
connection after each retry.

cbugg: close bug-917