Commit e043fa9
* fix(ingestion): release Engine resources on database switch (#27625)
* fix(ingestion): release engine resources on database switch
Close fairies in _connection_map and clear _inspector_map before
engine.dispose() in CommonDbSourceService.set_inspector/close. Dispose
alone does not free Inspector.info_cache or release checked-out
ConnectionFairies, leaving the old engine GC-pinned across DB switches
and triggering _finalize_fairy RecursionError at interpreter shutdown.
Eagerly fetch multi-DB name queries (MultiDBSource._execute_database_query
and SnowflakeSource.get_database_names_raw) so the cursor closes before
the caller invokes set_inspector, which disposes the engine the cursor
was bound to.
Also rebind scoped_session to the new engine so it doesn't keep the
disposed one alive via sessionmaker.bind.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* py format
* fix(ingestion): address PR review feedback from gitar-bot and Copilot
- Set self.engine = None after dispose in _release_engine (gitar-bot):
prevents close() from leaving a dangling disposed-engine reference
that would produce a confusing pool error on accidental later access.
- _FakeSource now has close() and is wrapped in a fixture that cleans
up its checked-out connection (Copilot #1): avoids resource warnings
and an interfering fairy across test teardown.
- Rewrite test_generator_survives_engine_dispose_mid_iteration as
test_generator_survives_connection_close_mid_iteration (Copilot #2):
Engine.dispose() does not close checked-out connections, so the old
test did not reproduce what _release_engine actually does. The real
regression is the explicit conn.close() on the fairy in
_connection_map before dispose. The new test closes the connection
mid-iteration, which is what fetchall() needs to survive.
- Switch the query in _FakeSource.get_database_names_raw and the
seeded INSERT assertions to the TEXT name column (Copilot #3):
_execute_database_query is typed Iterable[str]; testing on integer
ids obscured the actual contract.
- Update test_disposes_pool to assert surrogate.engine is None after
release (follows from the new self.engine = None behavior) and
verify the original pool's checkedout() is 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(ingestion): keep connection_obj in sync with engine across DB switches
self.connection_obj is set once in __init__ to the initial engine and
never updated. After set_inspector rebuilds self.engine, connection_obj
still points at the disposed original engine — pinning its dialect and
compiled_cache alive for the source's lifetime.
Rebind connection_obj when creating the new engine in set_inspector,
and clear it in _release_engine so close() leaves nothing dangling.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3df57da commit e043fa9
5 files changed
Lines changed: 659 additions & 10 deletions
File tree
- ingestion
- src/metadata/ingestion/source/database
- snowflake
- tests/unit/topology/database
Lines changed: 30 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
| |||
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
155 | | - | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | 158 | | |
160 | 159 | | |
| 160 | + | |
| 161 | + | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
163 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
164 | 190 | | |
165 | 191 | | |
166 | 192 | | |
| |||
781 | 807 | | |
782 | 808 | | |
783 | 809 | | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
| 810 | + | |
788 | 811 | | |
789 | 812 | | |
790 | 813 | | |
791 | | - | |
792 | 814 | | |
793 | 815 | | |
794 | 816 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
0 commit comments