pjfanning opened a new pull request, #1876:
URL: https://github.com/apache/pekko-connectors/pull/1876

   **Motivation:**
   
   `HBaseSourceLogic` acquires three resources and releases one:
   
   ```scala
   implicit val connection: Connection = connect(settings.conf)
   lazy val table: Table = getOrCreateTable(...).get
   
   override def preStart(): Unit =
     val scanner = table.getScanner(scan)   // local val, never closed
     results = scanner.iterator()
   
   override def postStop(): Unit =
     table.close()                          // connection never closed
   ```
   
   - The `Connection` is a `ConnectionImplementation` — a ZooKeeper connection, 
an `RpcClient` and a thread pool. Every materialization of `HTableStage.source` 
leaks one for the life of the JVM. `table` is only a thin per-connection 
handle, so closing it releases very little.
   - The `ResultScanner` is a local `val` that is never closed, so the 
server-side scanner lease is held on the RegionServer until it times out — on 
every run.
   
   The sibling `HBaseFlowStage.postStop` already closes **both** `table` and 
`connection`, so this is an omission in the source stage rather than a 
deliberate difference.
   
   **Modification:**
   
   Keep the scanner in a field and close all three in `postStop`, each 
independently so a failure to close one still releases the rest.
   
   Failures are logged rather than rethrown, matching `HBaseFlowStage`. Note 
the previous code called `failStage` from `postStop`, which is too late to have 
any effect.
   
   `table` is `lazy`, so a `tableOpened` flag records whether `preStart` 
actually forced it — otherwise `postStop` would *create* a table just to close 
it. If `preStart` fails part way (a `getScanner` throwing on a missing table is 
the common case), whatever was opened still gets released.
   
   The close sequence is extracted to `HBaseSourceLogic.closeAll` so it can be 
tested without an HBase cluster.
   
   **Result:**
   
   Connections, tables and scanners are released when the source stops, on both 
the normal and the failure path.
   
   **Tests:**
   
   Added `HBaseSourceLogicSpec` covering the ordinary path, a scanner that 
fails to close, a table that fails to close, and all three failing — each 
asserting the later resources are still closed.
   
   This needs no HBase server, which matters here: the hbase integration tests 
are commented out of the CI matrix (`check-build-test.yml`, pending 
akka/alpakka#2185), so a test requiring Docker would never run.
   
   4 tests pass. Ran `hbase/mimaReportBinaryIssues` (clean) and the module 
scalafmt checks.
   
   **References:**
   
   Compare `HBaseFlowStage.postStop`, which closes table and connection.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to