Backport several fixes and logging enhancements, and make the client hangup timeout configurable