shuwenwei opened a new pull request, #19247:
URL: https://github.com/apache/iotdb/pull/19247

   ## Problem
   
   `TableSessionPool.getSession()` borrows a raw `Session` from the underlying 
`SessionPool`, but the table-session path did not register that `Session` in 
`occupied`. A later `pool.close()` therefore only saw idle sessions and 
sessions tracked for old tree-model result sets. Active table sessions could 
remain open, and returning one after the pool had closed could put it back into 
the closed pool.
   
   A concrete failure sequence is:
   
   ```java
   ITableSessionPool pool = new TableSessionPoolBuilder()
       .nodeUrls(nodeUrls)
       .user(user)
       .password(password)
       .maxSize(1)
       .build();
   
   ITableSession session = pool.getSession();
   pool.close();
   session.close();
   ```
   
   Before this change:
   
   - `pool.close()` did not see the borrowed table session because it was 
absent from both `queue` and `occupied`.
   - `session.close()` then returned the connection to the already-closed pool, 
leaving it unmanaged and open.
   - Closing the wrapper twice, or closing it after a connection failure, could 
throw an NPE.
   - A failure while restoring SQL dialect/database could close the physical 
session without restoring the configured pool capacity.
   
   After this change, the borrowed session is tracked until release; 
`pool.close()` closes it, and releasing a session into a closed pool closes it 
directly instead of publishing it back into `queue`.
   
   The same cleanup logic also fixes an expected exception leak in tree-model 
`sortTablet()`:
   
   ```text
   maxSize=1
   sortTablet(tablet) throws IllegalArgumentException
   ```
   
   Before: the borrowed session was not returned, so subsequent operations 
waited until timeout even though `size == 1`. After: `try/finally` returns the 
session, allowing the next operation to borrow it normally.
   
   ## Changes
   
   - Track pooled table sessions in `occupied` from acquisition until wrapper 
release.
   - Make table-session close idempotent and safe after connection failures.
   - Release sessions through one path that removes `occupied`, reuses the 
connection only when safe, and replaces failed sessions while the pool remains 
open.
   - Close sessions directly when they are returned after the pool has closed.
   - Preserve pool capacity when SQL dialect/database restoration fails.
   - Ensure `sortTablet()` returns its session when sorting succeeds or throws.
   - Add lifecycle tests for pool close, repeated table-session close with 
`maxSize=1`, and `sortTablet()` failure recovery.
   
   ## Validation
   
   - `git diff --check` passed.
   - Spotless checks passed for `iotdb-client/session` and `integration-test`.
   - Tests were added but were not executed locally. CI will exercise them.
   


-- 
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]

Reply via email to