HADOOP-14727. Socket not closed properly when reading Configurations with BlockReaderRemote. Contributed by Jonathan Eagles.
This commit is contained in:
parent
0b67436068
commit
a3a9c976c3
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package org.apache.hadoop.conf;
|
package org.apache.hadoop.conf;
|
||||||
|
|
||||||
|
import com.ctc.wstx.io.StreamBootstrapper;
|
||||||
|
import com.ctc.wstx.io.SystemId;
|
||||||
import com.ctc.wstx.stax.WstxInputFactory;
|
import com.ctc.wstx.stax.WstxInputFactory;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
@ -94,7 +96,6 @@ import org.apache.hadoop.security.alias.CredentialProviderFactory;
|
||||||
import org.apache.hadoop.util.ReflectionUtils;
|
import org.apache.hadoop.util.ReflectionUtils;
|
||||||
import org.apache.hadoop.util.StringInterner;
|
import org.apache.hadoop.util.StringInterner;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
import org.codehaus.stax2.XMLInputFactory2;
|
|
||||||
import org.codehaus.stax2.XMLStreamReader2;
|
import org.codehaus.stax2.XMLStreamReader2;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -285,7 +286,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
* Specify exact input factory to avoid time finding correct one.
|
* Specify exact input factory to avoid time finding correct one.
|
||||||
* Factory is reusable across un-synchronized threads once initialized
|
* Factory is reusable across un-synchronized threads once initialized
|
||||||
*/
|
*/
|
||||||
private static final XMLInputFactory2 XML_INPUT_FACTORY = new WstxInputFactory();
|
private static final WstxInputFactory XML_INPUT_FACTORY =
|
||||||
|
new WstxInputFactory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to keep the information about the keys which replace the deprecated
|
* Class to keep the information about the keys which replace the deprecated
|
||||||
|
@ -2647,15 +2649,18 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
return parse(connection.getInputStream(), url.toString());
|
return parse(connection.getInputStream(), url.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private XMLStreamReader parse(InputStream is,
|
private XMLStreamReader parse(InputStream is, String systemIdStr)
|
||||||
String systemId) throws IOException, XMLStreamException {
|
throws IOException, XMLStreamException {
|
||||||
if (!quietmode) {
|
if (!quietmode) {
|
||||||
LOG.debug("parsing input stream " + is);
|
LOG.debug("parsing input stream " + is);
|
||||||
}
|
}
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return XML_INPUT_FACTORY.createXMLStreamReader(systemId, is);
|
SystemId systemId = SystemId.construct(systemIdStr);
|
||||||
|
return XML_INPUT_FACTORY.createSR(XML_INPUT_FACTORY.createPrivateConfig(),
|
||||||
|
systemId, StreamBootstrapper.getInstance(null, systemId, is), false,
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadResources(Properties properties,
|
private void loadResources(Properties properties,
|
||||||
|
|
|
@ -156,10 +156,12 @@ public class TestConfiguration extends TestCase {
|
||||||
declareProperty("prop", "A", "A");
|
declareProperty("prop", "A", "A");
|
||||||
endConfig();
|
endConfig();
|
||||||
|
|
||||||
InputStream in1 = new ByteArrayInputStream(writer.toString().getBytes());
|
InputStream in1 = Mockito.spy(new ByteArrayInputStream(
|
||||||
|
writer.toString().getBytes()));
|
||||||
Configuration conf = new Configuration(false);
|
Configuration conf = new Configuration(false);
|
||||||
conf.addResource(in1);
|
conf.addResource(in1);
|
||||||
assertEquals("A", conf.get("prop"));
|
assertEquals("A", conf.get("prop"));
|
||||||
|
Mockito.verify(in1, Mockito.times(1)).close();
|
||||||
InputStream in2 = new ByteArrayInputStream(writer.toString().getBytes());
|
InputStream in2 = new ByteArrayInputStream(writer.toString().getBytes());
|
||||||
conf.addResource(in2);
|
conf.addResource(in2);
|
||||||
assertEquals("A", conf.get("prop"));
|
assertEquals("A", conf.get("prop"));
|
||||||
|
|
Loading…
Reference in New Issue