Shopify/sarama — pull request #55 by graemej (2013-11-22 19:40:09+00:00)
Title: Add an option for a connect timeout

This is a proposal to include a connect timeout to NewClient().

It's motivated by a problem encountered by a developer with an unhealthy Kafka cluster that would accept connections, but never read/write from the socket. This would cause the NewClient() call to block indefinitely waiting on a response. The Java command-line tools eventually timed out out and reported an error which seems friendlier.

I've added a unit test to simulate this situation.

Summary of changes:
* Add a new `ConnectTimeout` field to the `ClientConfig` struct
* Add a new `connectTimeout ` field to the `Broker` struct
* Pass the timeout from the ClientConfig to the Broker in `NewClient()`
* The timeout value is applied to the first message processed by `responseReceiver()` and is removed immediately after the first message is received. Any errors encountered setting / clearing timeout values are percolated through the regular error reporting mechanism.