[
https://issues.apache.org/jira/browse/ZOOKEEPER-5139?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated ZOOKEEPER-5139:
--------------------------------------
Labels: pull-request-available (was: )
> {{QuorumPeer.QuorumServer.toString()}} (QuorumPeer.java, line 440 in 3.9.6)
> builds each server's address with no {{Locale}}
> ---------------------------------------------------------------------------------------------------------------------------
>
> Key: ZOOKEEPER-5139
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-5139
> Project: ZooKeeper
> Issue Type: Bug
> Affects Versions: 3.9.6
> Reporter: Eric Pugh
> Priority: Major
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Hi all... I am working on Solr's embracing of zookeeper embedded dynamic
> quorum, and as part of our testing we start solr with various locales.
> This ticket falls out of that... I believe that starting Solr in locale
> locale is a reasonable thing, but would understand if you said "we only do
> "en" or something everywhere. But there have been some other fixes to ZK
> over time that do take locale into account!
> {\{QuorumPeer.QuorumServer.toString()}} (QuorumPeer.java, line 440 in 3.9.6)
> builds each server's address with no \{{Locale}}:
> {code:java}
> String.format("%s:%d:%d", delimitedHostString(addrList.get(i)),
> addrList.get(i).getPort(), electionAddrList.get(i).getPort())
> {code}
> {\{%d}} uses the JVM's default locale. Under a locale whose default numbering
> system isn't ASCII, for example \{{as-IN}} (Assamese) or \{{bn-BD}}
> (Bengali), the quorum and election ports are written in native digits. The
> client port is appended by concatenation, so it stays ASCII:
> {noformat}
> server.2=127.0.0.1:১৯৩৯০:১৯৪০০:participant;0.0.0.0:19380
> {noformat}
> This string is what \{{QuorumVerifier.toString()}} publishes as the dynamic
> config, in \{{/zookeeper/config}} and \{{zoo.cfg.dynamic.*}}. Readers can't
> parse it. For example, Curator's \{{EnsembleTracker}} loads the config bytes
> into \{{java.util.Properties}}, which decodes them as ISO-8859-1. The digits
> arrive mangled, \{{Integer.parseInt}} throws, and \{{QuorumServer}} reports:
> {noformat}
> org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Address
> unresolved: 127.0.0.1:১৯৩৯০
> at
> org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.initializeWithAddressString(QuorumPeer.java:356)
> at
> org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:283)
> at
> org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:278)
> at
> org.apache.zookeeper.server.quorum.flexible.QuorumMaj.<init>(QuorumMaj.java:96)
> at
> org.apache.curator.framework.imps.EnsembleTracker.processConfigData(EnsembleTracker.java:190)
> ...
> {noformat}
> ZooKeeper itself reads \{{zoo.cfg.dynamic.*}} the same way on restart
> (\{{QuorumPeerConfig}} calls \{{Properties.load(FileInputStream)}}), so a
> restarted server mangles its own ports too. Properties-format text is ASCII
> by convention, so the writer should produce ASCII rather than every reader
> changing its decoding. And even when the bytes are decoded correctly, the
> result is not portable: a config written under one locale must be read back
> by peers and clients that may use another.
> h3. Impact
> With \{{reconfigEnabled=true}}, clients can't follow ensemble changes, and
> tools that read the dynamic config see no members. Apache Solr hit this with
> its embedded ZooKeeper quorum (SOLR-18094). Its randomized tests run under
> random default locales, and joining a node to a running ensemble failed under
> \{{as-IN}}. Solr now skips those tests under such locales and documents
> \{{-Duser.language=en}} as a workaround.
> h3. Reproduce
> Start a ZooKeeper 3.9.6 ensemble with \{{reconfigEnabled=true}} in a JVM run
> with \{{-Duser.language=as -Duser.country=IN}}, then read
> \{{/zookeeper/config}}: the quorum and election ports are not ASCII. Or, in
> isolation:
> {code:java}
> String.format(Locale.forLanguageTag("as-IN"), "%d", 19390); // "১৯৩৯০"
> {code}
> h3. Related
> * ZOOKEEPER-1206: the same bug class, fixed in 2011 for sequential znode
> names (\{{String.format(Locale.ENGLISH, "%010d", ...)}} in
> \{{PrepRequestProcessor}}), also found through Lucene/Solr's randomized
> locales.
> * ZOOKEEPER-5113 (open, PR #2481): default-locale \{{toLowerCase()}} in audit
> logs, \{{mntr}} and \{{zabstate}}. That PR touches \{{QuorumPeer}} but not
> this \{{String.format}} call.
> h3. Suggested fix
> Pass \{{Locale.ROOT}}:
> {code:java}
> String.format(Locale.ROOT, "%s:%d:%d", ...)
> {code}
> Other \{{String.format}} calls whose output is parsed back may deserve the
> same check. Running forbidden-apis with its JDK "unsafe" signatures would
> catch them.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)