Skip to content

Commit 1c9ba1f

Browse files
fix: reset drainScheduled if OpExecutor.drain exits abruptly
handler.uncaught is the last-resort recovery for a task throw; it cancels the chain, which drives Done.onStart, which calls listener.onClose. If the user's terminal listener also throws, the throw escapes the handler and exits drain() before reaching the `r == null` branch that clears drainScheduled. The flag stays set and every subsequent execute() queues without rescheduling — the OpExecutor is wedged. Per-op lifecycle today has no work after terminal close, so the wedge leaks nothing observable. Fixing it for symmetry with scheduleDrainLocked (which already resets drainScheduled on a backing.execute throw) and to keep the contract robust if a future handler can throw on a non-terminal op. Caught by gemini-code-assist on PR googleapis#13604.
1 parent 1251fe7 commit 1c9ba1f

1 file changed

Lines changed: 28 additions & 17 deletions

File tree

  • java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/middleware

‎java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/middleware/OpExecutor.java‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,38 @@ private void scheduleDrainLocked() {
120120
}
121121

122122
private void drain() {
123-
while (true) {
124-
Runnable r;
125-
synchronized (queue) {
126-
r = queue.poll();
127-
if (r == null) {
128-
drainScheduled = false;
129-
return;
123+
// If the loop exits abruptly (only reachable if handler.uncaught itself throws), reset
124+
// drainScheduled before propagating so a subsequent execute() reschedules instead of
125+
// queueing into a wedged executor. Symmetric with scheduleDrainLocked's reset on backing
126+
// throw.
127+
try {
128+
while (true) {
129+
Runnable r;
130+
synchronized (queue) {
131+
r = queue.poll();
132+
if (r == null) {
133+
drainScheduled = false;
134+
return;
135+
}
136+
runningThread = Thread.currentThread();
130137
}
131-
runningThread = Thread.currentThread();
132-
}
133-
try {
134138
try {
135-
r.run();
136-
} catch (Throwable t) {
137-
handler.uncaught(t);
138-
}
139-
} finally {
140-
synchronized (queue) {
141-
runningThread = null;
139+
try {
140+
r.run();
141+
} catch (Throwable t) {
142+
handler.uncaught(t);
143+
}
144+
} finally {
145+
synchronized (queue) {
146+
runningThread = null;
147+
}
142148
}
143149
}
150+
} catch (Throwable t) {
151+
synchronized (queue) {
152+
drainScheduled = false;
153+
}
154+
throw t;
144155
}
145156
}
146157

0 commit comments

Comments
 (0)