You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0ee9faf
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/api/Client.java
+13-2Lines changed: 13 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -291,15 +291,26 @@ public void close() {
291
291
// to a terminal Done — that delivery hops through op executor → userCallbackExecutor, both
292
292
// of which must still be alive at this moment.
293
293
//
294
+
// channelPool.close() runs BEFORE userCallbackExecutor.close() so any classic (non-session)
295
+
// gRPC call still in flight has its StreamListener.onClose delivered while the callback
296
+
// executor is alive — otherwise the callback lands on a shut-down executor, hits REE, and
297
+
// the caller's listener never sees a terminal onClose. Phase 2 only drains session-based
298
+
// pools; classic callables share this same userCallbackExecutor.
299
+
//
294
300
// userCallbackExecutor.close() next, with a 5s drain to catch the listener.onClose tasks
295
-
// queued by both the session drain (Phase 2) and the just-fired retry shutdowns.
301
+
// queued by the session drain (Phase 2), the just-fired retry shutdowns, and channel
302
+
// teardown.
303
+
//
304
+
// metrics.close() and configManager.close() don't depend on the shared channelPool (metrics
305
+
// uses its own OTel exporter channel; configManager should have finished any config RPCs
306
+
// before close).
296
307
//
297
308
// backgroundExecutor must close last because it's the timer's dispatcher and the op
Copy file name to clipboardExpand all lines: java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/session/SessionImpl.java
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -294,6 +294,12 @@ public void forceClose(CloseSessionRequest closeReason) {
Copy file name to clipboardExpand all lines: java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/session/SessionList.java
+47-33Lines changed: 47 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -112,8 +112,12 @@ public Optional<SessionHandle> checkoutSession(AfeHandle afeHandle) {
112
112
113
113
/** Closes all the sessions with this reason. */
114
114
voidclose(CloseSessionRequestreq) {
115
-
// Notify all sessions to close and have the callbacks clean up the rest of the state
116
-
for (SessionHandles : allSessions) {
115
+
// Snapshot before iterating: session.close(req) enqueues on sessionSyncContext, and
116
+
// io.grpc.SynchronizationContext.execute drains inline when the caller is the drainer. A
117
+
// pre-existing queued task (e.g. dispatchStreamClosed from a transport error just before
118
+
// close, or a heartbeat-miss forceClose that already fired) can drain here and remove its
119
+
// handle via onSessionClosed → allSessions.remove, tripping a fail-fast iterator CME.
120
+
for (SessionHandles : newArrayList<>(allSessions)) {
117
121
s.getSession().close(req);
118
122
}
119
123
}
@@ -239,41 +243,51 @@ void onSessionClosing() {
239
243
}
240
244
241
245
voidonSessionClosed(SessionStateprevState) {
242
-
if (inExpectedCount) {
243
-
poolStats.expectedCapacity--;
244
-
inExpectedCount = false;
245
-
}
246
-
// only update counts after the session started and has an afe associated
247
-
afe.ifPresent(afeHandle -> afeHandle.refCount--);
248
-
249
-
// NOTE: don't need to update vRpc counters, onVRpcFinish will have been invoked already
250
-
switch (prevState) {
251
-
caseNEW:
252
-
thrownewIllegalStateException("NEW session was closed");
253
-
caseSTARTING:
254
-
poolStats.startingCount--;
255
-
break;
256
-
caseREADY:
257
-
{
258
-
AfeHandleafeHandle = afe.get();
259
-
// If the session was available & idle, then we need to remove it
260
-
if (afeHandle.sessions.remove(this)) {
261
-
poolStats.readyCount--;
262
-
if (afeHandle.sessions.isEmpty()) {
263
-
afesWithReadySessions.remove(afeHandle);
246
+
// Always drop from allSessions on the way out, even if the branch below throws — otherwise a
247
+
// stranded handle blocks drainedFuture and pool.awaitTerminated hangs until the shared close
248
+
// deadline elapses.
249
+
try {
250
+
if (inExpectedCount) {
251
+
poolStats.expectedCapacity--;
252
+
inExpectedCount = false;
253
+
}
254
+
// only update counts after the session started and has an afe associated
255
+
afe.ifPresent(afeHandle -> afeHandle.refCount--);
256
+
257
+
// NOTE: don't need to update vRpc counters, onVRpcFinish will have been invoked already
258
+
switch (prevState) {
259
+
caseNEW:
260
+
thrownewIllegalStateException("NEW session was closed");
261
+
caseSTARTING:
262
+
poolStats.startingCount--;
263
+
break;
264
+
caseREADY:
265
+
{
266
+
// afe may be empty if SessionPoolImpl.onSessionReady early-returned on poolState !=
267
+
// STARTED (pool closed after SessionImpl transitioned to READY but before
268
+
// handle.onSessionStarted ran). Skip the AFE bookkeeping cleanly rather than NPE.
269
+
if (afe.isPresent()) {
270
+
AfeHandleafeHandle = afe.get();
271
+
// If the session was available & idle, then we need to remove it
0 commit comments