Apply ZOOKEEPER-1894.

https://issues.apache.org/jira/secure/attachment/12635918/ZOOKEEPER-1894.patch