Repository navigation
Commit 013b49b
authored
fix(spanner): prevent stream leaks and race conditions on result set close (#14665)
Fixes several race conditions, potential stream leaks, and state loss
when closing streaming result sets:
1. Early Close Race Condition: If ResultSet.close() was called before
asynchronous gRPC stream initialization finished (before setCall was
invoked), the cancellation was silently dropped because the call
reference was still null. When setCall ran moments later, the stream
remained open and was never cancelled. Now, closed state is tracked so
that setCall immediately cancels the stream if closed early.
2. Concurrent Close Idempotency: close() is now synchronized and
extracts the call reference atomically, guaranteeing call.cancel() is
executed at most once, and executing the cancellation outside the lock
to prevent deadlocks.
3. Superfluous Cancellation on Completed Streams: The call handle is now
cleared as soon as a PartialResultSet with last=true is consumed,
avoiding unnecessary RPC cancellations when closing after reading the
final chunk without an extra next() call.
4. END_OF_STREAM Queue Deduplication: Atomically deduplicate
END_OF_STREAM markers to avoid queue overflow or stalls when
prefetchChunks is configured to small values (e.g. prefetchChunks = 1).
5. Inlined Begin Transaction State on Close: In GrpcResultSet.close(),
capture withBeginTransaction before closing the underlying iterator so
listener.onDone() properly unblocks any threads waiting for inlined
transaction IDs.1 parent 312b5ea commit 013b49b
6 files changed
Lines changed: 1231 additions & 40 deletions
File tree
- java-spanner/google-cloud-spanner/src
- main/java/com/google/cloud/spanner
- test/java/com/google/cloud/spanner
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
41 | 76 | | |
42 | 77 | | |
43 | 78 | | |
| |||
47 | 82 | | |
48 | 83 | | |
49 | 84 | | |
50 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
51 | 89 | | |
52 | 90 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
57 | 94 | | |
58 | 95 | | |
59 | 96 | | |
| |||
84 | 121 | | |
85 | 122 | | |
86 | 123 | | |
87 | | - | |
88 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
89 | 146 | | |
90 | 147 | | |
91 | 148 | | |
| |||
94 | 151 | | |
95 | 152 | | |
96 | 153 | | |
97 | | - | |
98 | | - | |
| 154 | + | |
99 | 155 | | |
100 | | - | |
101 | | - | |
| 156 | + | |
102 | 157 | | |
103 | 158 | | |
104 | 159 | | |
105 | 160 | | |
| 161 | + | |
106 | 162 | | |
107 | 163 | | |
108 | 164 | | |
109 | 165 | | |
110 | | - | |
111 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
112 | 179 | | |
113 | 180 | | |
114 | 181 | | |
115 | 182 | | |
116 | 183 | | |
117 | 184 | | |
118 | | - | |
119 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
120 | 200 | | |
121 | 201 | | |
122 | 202 | | |
| |||
131 | 211 | | |
132 | 212 | | |
133 | 213 | | |
134 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
135 | 235 | | |
136 | | - | |
137 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
138 | 239 | | |
139 | 240 | | |
140 | 241 | | |
141 | 242 | | |
| 243 | + | |
142 | 244 | | |
143 | | - | |
| 245 | + | |
144 | 246 | | |
145 | 247 | | |
146 | 248 | | |
147 | 249 | | |
148 | 250 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 251 | + | |
153 | 252 | | |
| 253 | + | |
154 | 254 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
159 | 258 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | 259 | | |
164 | 260 | | |
165 | 261 | | |
| |||
179 | 275 | | |
180 | 276 | | |
181 | 277 | | |
182 | | - | |
183 | | - | |
| 278 | + | |
184 | 279 | | |
185 | 280 | | |
186 | 281 | | |
187 | 282 | | |
188 | 283 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 284 | + | |
192 | 285 | | |
193 | 286 | | |
194 | 287 | | |
| |||
203 | 296 | | |
204 | 297 | | |
205 | 298 | | |
206 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
207 | 313 | | |
208 | 314 | | |
209 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
| |||
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
122 | 128 | | |
123 | 129 | | |
124 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
125 | 192 | | |
0 commit comments