PDGGK opened a new pull request, #35:
URL: https://github.com/apache/iotdb-client-nodejs/pull/35

   This fixes the second item in #22.
   
   `close()` cleared the wait queue without settling the queued promises. A 
caller that is waiting in `getSession()` when the pool is closed stays pending 
until `waitTimeout` (60 s by default), and then fails with `Timeout waiting for 
available session`, which points at pool exhaustion rather than at the close. 
If nothing else keeps the process alive, the promise never settles at all, 
because the wait timer is unref'd: the process exits and the code after `await 
pool.getSession()` does not run.
   
   I checked this against IoTDB 2.0.11 with a pool of size 1 and `waitTimeout: 
10000`: one call holds the only session, a second call waits, and then the pool 
is closed.
   
   - On `develop`, the second call was rejected after 10,001 ms with `Timeout 
waiting for available session`. Without a timer keeping the process up, the 
process exited with code 0 after 204 ms and the call never settled.
   - With this change, the call is rejected right away with `SessionPool is 
closed` in both cases.
   
   ### Change
   
   The waiters in the queue now accept either a session or an error. `close()` 
rejects them with `<pool name> is closed` as soon as it starts, before it waits 
for the sessions to close. At the end, where it used to clear the queue, it 
rejects them again, for callers that started waiting while the sessions were 
being closed.
   
   ### Not covered
   
   `getSession()` calls made while `close()` is running, or after it has 
returned, still behave as on `develop`. A session released during `close()` can 
be handed to a caller that started waiting in the meantime, and a call after 
`close()` opens a new session. Rejecting those as well needs a closed state in 
the pool, which changes what the pool does after `close()`, so I have kept it 
out of this PR.
   
   ### Tests
   
   There are two new tests in `BaseSessionPoolLifecycle.test.ts`:
   
   - A caller already waiting is rejected while `close()` is still waiting for 
a session to close.
   - A caller that starts waiting during `close()` is rejected when `close()` 
returns.
   
   Both fail on `develop`, where the call is still pending after 1 s. If only 
the first rejection is kept, the second test fails; if only the second is kept, 
the first test fails.
   
   `npm run test:unit` passes (175 tests). The `SessionPool` and 
`TableSessionPool` e2e tests pass against IoTDB 2.0.11 (12 and 9 tests). 
`Should execute query using pool` expects `SHOW DATABASES` to return a row, so 
without a tree-model database it fails with and without this change; I created 
one for these runs. ESLint reports no errors, and Prettier reports nothing new.
   


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