From 686e77108a339516e4a78751fc4982072e171e97 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Fri, 17 Oct 2014 16:05:31 +0000 Subject: [PATCH] HBASE-12274 Race between RegionScannerImpl#nextInternal() and RegionScannerImpl#close() may produce null pointer exception --- .../java/org/apache/hadoop/hbase/regionserver/HRegion.java | 4 ++++ .../org/apache/hadoop/hbase/regionserver/RSRpcServices.java | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 28c6cc50e65..67ff2cb2d6b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -4108,6 +4108,10 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { // @Override public boolean nextRaw(List outResults, int limit) throws IOException { + if (storeHeap == null) { + // scanner is closed + throw new UnknownScannerException("Scanner was closed"); + } boolean returnResult; if (outResults.isEmpty()) { // Usually outResults is empty. This is true when next is called diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index eae6e960ea1..dc4bf7b7683 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -2164,9 +2164,12 @@ public class RSRpcServices implements HBaseRPCErrorHandler, if (rsh != null) { try { RegionScanner scanner = rsh.s; + LOG.warn(scannerName + " encountered " + ie.getMessage() + ", closing ..."); scanner.close(); regionServer.leases.cancelLease(scannerName); - } catch (IOException e) {} + } catch (IOException e) { + LOG.warn("Getting exception closing " + scannerName, e); + } } } throw new ServiceException(ie);