Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/main/scala/kafka/zookeeper/ZooKeeperClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ class ZooKeeperClient(connectString: String,
metricNames += "SessionState"

expiryScheduler.startup()
waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)
try {
waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)
} catch {
case e: ZooKeeperClientTimeoutException =>
close()
throw e
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be a finally instead of catch, I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it some more, we actually need to shutdown the scheduler too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can call ZooKeeperClient.close()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we don't need the block for try, e.g.

try waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)
catch {
  case e: Throwable =>
    close()
    throw e
}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating, I still think we should use a finally block instead of catching a specific exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait. I was wrong, we can't use finally here. But we should probably catch a more general exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can user ZooKeeperClientException, which parent is parent class for zk excpetions

@ijuma ijuma Jul 21, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, as other exceptions can be thrown too. But to be honest, we might as well catch Throwable since we rethrow he exception anyway. We just want to avoid leaking the resource.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR with Throwable . Not sure, if we can catch parent constructor exception in subclass constructor. For now, added a test based on zk thread count.

override def metricName(name: String, metricTags: scala.collection.Map[String, String]): MetricName = {
explicitMetricName(metricGroup, metricType, name, metricTags)
Expand Down