Commit 8ec57f0
authored
fix(csharp): always send CloseOperation from DatabricksCompositeReader.Dispose (#360)
## Problem
`DatabricksCompositeReader.Dispose` only called `CloseOperation` when
`_activeReader` was `null`. When a `CloudFetchReader` was active, it
delegated `Dispose` to the reader — but `CloudFetchReader` is
protocol-agnostic (it downloads from cloud storage over HTTP) and never
sends `CloseOperation` to the Thrift endpoint.
**Result:** every CloudFetch query orphaned the server-side operation
for ~1 hour, until SQL Gateway's `driver-router` detected inactivity and
fired `CommandInactivityTimeout`. This produced
`thriftOperationCloseReason=CommandInactivityTimeout` in usage logs for
all CloudFetch queries in connection-pooled scenarios (where
`CloseSession` is never sent).
## Root cause
The bug was introduced in commit `0039ee3` — *"refactor(csharp): make
CloudFetch pipeline protocol-agnostic (#14)"*.
Before that commit:
- `BaseDatabricksReader` had a public `CloseOperationAsync()` method
that sent the Thrift RPC
- `DatabricksCompositeReader.Dispose` called
`_activeReader.CloseOperationAsync()` — correct for both
`DatabricksReader` and `CloudFetchReader` (both inherited from
`BaseDatabricksReader`)
The protocol-agnostic refactor made three changes that together caused
the regression:
1. **Removed** `CloseOperationAsync()` from `BaseDatabricksReader`
2. Changed `DatabricksCompositeReader.Dispose` to call
`_activeReader.Dispose()` instead of
`_activeReader.CloseOperationAsync()`, with the comment *"Have the
contained reader close the operation to avoid duplicate calls"*
3. Made `CloudFetchReader` protocol-agnostic (no Thrift dependency) —
its `Dispose` only cleans up HTTP/download resources and never sends
`CloseOperation`
`DatabricksReader` got its own `CloseOperationAsync()` called from
`Dispose`, so inline results remained correct. But the CloudFetch path
silently lost its cleanup.
## Fix
Move `CloseOperation` ownership entirely to
`DatabricksCompositeReader.Dispose`, which holds both `_statement`
(Thrift client) and `_response` (operation handle).
`HiveServer2Reader.CloseOperationAsync` already handles the
DirectResults case correctly — it is a no-op when the server already
closed the operation inline.
Remove `CloseOperation` from `DatabricksReader.Dispose` to avoid a
duplicate call; `DatabricksReader` is only ever constructed from
`DatabricksCompositeReader.CreateDatabricksReader`.
## Behavior after fix
| Result delivery path | CloseOperation sent? |
|---|---|
| Inline + DirectResults enabled | No (server closed inline —
`CloseOperationAsync` is a no-op) |
| Inline + DirectResults disabled | Yes (explicit Thrift RPC from
composite reader) |
| CloudFetch | Yes (explicit Thrift RPC from composite reader — was
previously missing) |
## Testing
Validated with 4 new proxy-based regression tests in
`databricks/databricks-driver-test` (CLOUDFETCH-013 through 016) that
simulate connection pooling (reader disposed without closing the
connection) and assert the correct number of `CloseOperation` Thrift
calls for each path.1 parent d4083ce commit 8ec57f0
File tree
3 files changed
+198
-12
lines changed- csharp
- src/Reader
- test/E2E
3 files changed
+198
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | 244 | | |
249 | 245 | | |
250 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 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 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 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 | + | |
0 commit comments