- add deferred function to close the client connection on error - ensure proper cleanup for all client functions