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 814f43eb173b..8fe2efc41f1e 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 @@ -3203,8 +3203,16 @@ private Pair newRegionScanner(ScanRequest request, RegionScannerImpl coreScanner = region.getScanner(scan); Shipper shipper = coreScanner; RegionScanner scanner = coreScanner; - if (region.getCoprocessorHost() != null) { - scanner = region.getCoprocessorHost().postScannerOpen(scan, scanner); + try { + if (region.getCoprocessorHost() != null) { + scanner = region.getCoprocessorHost().postScannerOpen(scan, scanner); + } + } catch (Exception e) { + // Although region coprocessor is for advanced users and they should take care of the + // implementation to not damage the HBase system, closing the scanner on exception here does + // not have any bad side effect, so let's do it + scanner.close(); + throw e; } long scannerId = scannerIdGenerator.generateNewScannerId(); builder.setScannerId(scannerId);