From d33aec93f1404ff77541ef8c9f0fe2c49198b766 Mon Sep 17 00:00:00 2001 From: Surendra Singh Lilhore Date: Fri, 28 Feb 2020 18:33:06 +0530 Subject: [PATCH] HDFS-15199. NPE in BlockSender. Contributed by Ayush Saxena. --- .../hdfs/server/datanode/BlockSender.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java index 2cb4100f431..ad9be88c087 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockSender.java @@ -664,18 +664,21 @@ class BlockSender implements java.io.Closeable { * It was done here because the NIO throws an IOException for EPIPE. */ String ioem = e.getMessage(); - /* - * If we got an EIO when reading files or transferTo the client socket, - * it's very likely caused by bad disk track or other file corruptions. - */ - if (ioem.startsWith(EIO_ERROR)) { - throw new DiskFileCorruptException("A disk IO error occurred", e); - } - if (!ioem.startsWith("Broken pipe") && !ioem.startsWith("Connection reset")) { - LOG.error("BlockSender.sendChunks() exception: ", e); - datanode.getBlockScanner().markSuspectBlock( - ris.getVolumeRef().getVolume().getStorageID(), - block); + if (ioem != null) { + /* + * If we got an EIO when reading files or transferTo the client + * socket, it's very likely caused by bad disk track or other file + * corruptions. + */ + if (ioem.startsWith(EIO_ERROR)) { + throw new DiskFileCorruptException("A disk IO error occurred", e); + } + if (!ioem.startsWith("Broken pipe") + && !ioem.startsWith("Connection reset")) { + LOG.error("BlockSender.sendChunks() exception: ", e); + datanode.getBlockScanner().markSuspectBlock( + ris.getVolumeRef().getVolume().getStorageID(), block); + } } } throw ioeToSocketException(e);