Commit d328e3b
authored
fix(bigquery): dbapi socket leak (#17921)
## Problem
The system test `test_dbapi_connection_does_not_leak_sockets` fails
intermittently because network connections remain in the `ESTABLISHED`
state even after `connection.close()` is called. This is likely due to
the underlying gRPC (remote procedure call) transport not being
immediately closed, or delays in Garbage Collection (cleaning up unused
memory).
## Solution
This Pull Request updates `Connection.close()` to explicitly close the
underlying gRPC channel (`transport._grpc_channel`) if it exists on the
BigQuery Storage client. This ensures that the connection is closed
immediately and resources are released deterministically.
## Notes to Reviewers
- This change explicitly targets the underlying gRPC channel to bypass
potential delays caused by transport interceptors or non-deterministic
garbage collection.
- It addresses intermittent test failures caused by lingering
`ESTABLISHED` sockets.
- Also includes several linting revisions (sorry).
Sample debug info from traceback:
```
E --- Socket Leak Debug Info ---
E Start Count: 6
E End Count: 7
E Current Connections:
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=48550), Raddr: addr(ip='74.125.195.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=53976), Raddr: addr(ip='173.194.43.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=54818), Raddr: addr(ip='74.125.199.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=43762), Raddr: addr(ip='142.251.188.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=53946), Raddr: addr(ip='173.194.43.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=54792), Raddr: addr(ip='74.125.199.95', port=443)
E Status: ESTABLISHED, Laddr: addr(ip='10.138.0.14', port=48524), Raddr: addr(ip='74.125.195.95', port=443)
```1 parent ff58ec9 commit d328e3b
4 files changed
Lines changed: 73 additions & 38 deletions
File tree
- packages/google-cloud-bigquery
- google/cloud/bigquery/dbapi
- tests/unit
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
87 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
Lines changed: 12 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 32 | | |
36 | | - | |
| 33 | + | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| |||
105 | 103 | | |
106 | 104 | | |
107 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
| |||
Lines changed: 30 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
44 | | - | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
| 90 | + | |
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
| |||
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
107 | | - | |
| 105 | + | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
| |||
124 | 122 | | |
125 | 123 | | |
126 | 124 | | |
127 | | - | |
128 | | - | |
| 125 | + | |
129 | 126 | | |
130 | 127 | | |
131 | 128 | | |
| |||
155 | 152 | | |
156 | 153 | | |
157 | 154 | | |
158 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
162 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| |||
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
179 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
180 | 195 | | |
181 | 196 | | |
182 | 197 | | |
| |||
187 | 202 | | |
188 | 203 | | |
189 | 204 | | |
190 | | - | |
| 205 | + | |
| 206 | + | |
191 | 207 | | |
192 | 208 | | |
193 | 209 | | |
| |||
Lines changed: 19 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
180 | 178 | | |
181 | 179 | | |
182 | 180 | | |
183 | | - | |
184 | | - | |
| 181 | + | |
185 | 182 | | |
186 | 183 | | |
187 | 184 | | |
| |||
193 | 190 | | |
194 | 191 | | |
195 | 192 | | |
196 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
197 | 198 | | |
198 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
199 | 204 | | |
200 | 205 | | |
201 | 206 | | |
| |||
519 | 524 | | |
520 | 525 | | |
521 | 526 | | |
522 | | - | |
523 | 527 | | |
| 528 | + | |
524 | 529 | | |
525 | 530 | | |
526 | 531 | | |
| |||
533 | 538 | | |
534 | 539 | | |
535 | 540 | | |
536 | | - | |
537 | 541 | | |
| 542 | + | |
538 | 543 | | |
539 | 544 | | |
540 | 545 | | |
| |||
563 | 568 | | |
564 | 569 | | |
565 | 570 | | |
566 | | - | |
567 | 571 | | |
| 572 | + | |
568 | 573 | | |
569 | 574 | | |
570 | 575 | | |
| |||
607 | 612 | | |
608 | 613 | | |
609 | 614 | | |
| 615 | + | |
610 | 616 | | |
611 | 617 | | |
612 | | - | |
613 | 618 | | |
614 | 619 | | |
615 | 620 | | |
| |||
637 | 642 | | |
638 | 643 | | |
639 | 644 | | |
640 | | - | |
641 | 645 | | |
642 | | - | |
643 | | - | |
| 646 | + | |
644 | 647 | | |
645 | 648 | | |
646 | 649 | | |
| |||
702 | 705 | | |
703 | 706 | | |
704 | 707 | | |
705 | | - | |
| 708 | + | |
706 | 709 | | |
707 | 710 | | |
708 | 711 | | |
| |||
722 | 725 | | |
723 | 726 | | |
724 | 727 | | |
725 | | - | |
| 728 | + | |
726 | 729 | | |
727 | 730 | | |
728 | 731 | | |
| |||
932 | 935 | | |
933 | 936 | | |
934 | 937 | | |
935 | | - | |
936 | 938 | | |
| 939 | + | |
937 | 940 | | |
938 | 941 | | |
939 | 942 | | |
0 commit comments