HBASE-13601 Connection leak during log splitting. (Abhishek Singh Chouhan)

This commit is contained in:
Lars Hofhansl 2015-04-30 17:05:05 -07:00
parent aabf6ea2f6
commit 235dc9734f
1 changed files with 10 additions and 1 deletions

View File

@ -278,6 +278,7 @@ public class WALFactory {
long startWaiting = EnvironmentEdgeManager.currentTime(); long startWaiting = EnvironmentEdgeManager.currentTime();
long openTimeout = timeoutMillis + startWaiting; long openTimeout = timeoutMillis + startWaiting;
int nbAttempt = 0; int nbAttempt = 0;
FSDataInputStream stream = null;
while (true) { while (true) {
try { try {
if (lrClass != ProtobufLogReader.class) { if (lrClass != ProtobufLogReader.class) {
@ -286,7 +287,7 @@ public class WALFactory {
reader.init(fs, path, conf, null); reader.init(fs, path, conf, null);
return reader; return reader;
} else { } else {
FSDataInputStream stream = fs.open(path); stream = fs.open(path);
// Note that zero-length file will fail to read PB magic, and attempt to create // Note that zero-length file will fail to read PB magic, and attempt to create
// a non-PB reader and fail the same way existing code expects it to. If we get // a non-PB reader and fail the same way existing code expects it to. If we get
// rid of the old reader entirely, we need to handle 0-size files differently from // rid of the old reader entirely, we need to handle 0-size files differently from
@ -300,6 +301,14 @@ public class WALFactory {
return reader; return reader;
} }
} catch (IOException e) { } catch (IOException e) {
try {
if (stream != null) {
stream.close();
}
} catch (IOException exception) {
LOG.warn("Could not close FSDataInputStream" + exception.getMessage());
LOG.debug("exception details", exception);
}
String msg = e.getMessage(); String msg = e.getMessage();
if (msg != null && (msg.contains("Cannot obtain block length") if (msg != null && (msg.contains("Cannot obtain block length")
|| msg.contains("Could not obtain the last block") || msg.contains("Could not obtain the last block")