{{ message }}
Commit 56cbea8
authored
fix(rab): run async background boundary refresh on detached session (#17441)
When AuthorizedSession.request() makes an API call, it runs inside a
temporary aiohttp ClientSession block. If our background Regional Access
Boundary (RAB) refresh worker naively shares this exact same session, a
fast primary call (like an instant 401/403 or a quick CRM check) will
exit its block and close the active socket mid-flight. This causes the
background worker to silently fail with "RuntimeError: Session is
closed" and forces the RAB manager into a 15-minute cooldown.
This commit resolves the race condition and ensures safe connection lifecycle
management:
- Shifted the cloning block to run synchronously inside start_refresh,
capturing a fresh, independent ClientSession before the foreground thread
can close the source transport.
- Added a _clone() method to async Request adapters (both modern and legacy)
to copy proxy settings and trace configurations while enforcing connector limits.
- Prevented resource leaks on task creation failures by capturing exceptions
in start_refresh and closing the cloned session synchronously.
- Refactored the close wrapper to inspect and await generic awaitables
(such as asyncio.Future) returned by custom or third-party transports.
- Aligned exception behaviors by raising a wrapped TransportError directly
when calling a closed instance of the legacy aiohttp_requests adapter.
- Ensured the cloned transport is cleanly closed in a finally block after the
background lookup settles.1 parent b50cf1a commit 56cbea8
9 files changed
Lines changed: 1025 additions & 4 deletions
File tree
- packages/google-auth
- google/auth
- aio/transport
- transport
- tests_async
- transport
- tests
- transport/aio
Lines changed: 85 additions & 3 deletions
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
Lines changed: 90 additions & 0 deletions

0 commit comments