From 3510db4d2d40a95f2b7e31443e190a6174e1998c Mon Sep 17 00:00:00 2001 From: Pankaj Date: Fri, 15 Apr 2022 11:34:25 +0530 Subject: [PATCH] HBASE-26944 Possible resource leak while creating new region scanner (#4339) * HBASE-26944 Possible resource leak while creating new region scanner Signed-off-by: Duo Zhang (cherry picked from commit 62e3efccef766e580642a8b7cb5654c96e47687d) --- .../hadoop/hbase/regionserver/RSRpcServices.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 b6190f0374e..53ce61eb3f9 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 @@ -3233,8 +3233,16 @@ public class RSRpcServices implements HBaseRPCErrorHandler, 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);