fixes FD leak in RPC client

FD leak due to sockets not getting closed
on the rpc client
FIXRM #8107
conditional wrapping

as per egypt's catch
slight rearrangement
damnit brandon turner
"fix" indentation to make egypt happy
Land 2029, rpc client file descriptor leak