Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connections in datasources #397

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

anthonyburdi
Copy link
Member

No description provided.

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.00%. Comparing base (cbfdb09) to head (a72fcc4).

✅ All tests successful. No failed tests found.

Files Patch % Lines
...pectations_cloud/agent/actions/list_table_names.py 75.00% 1 Missing ⚠️
...expectations_cloud/agent/actions/run_checkpoint.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #397      +/-   ##
==========================================
+ Coverage   87.97%   88.00%   +0.02%     
==========================================
  Files          26       26              
  Lines        1031     1050      +19     
==========================================
+ Hits          907      924      +17     
- Misses        124      126       +2     
Flag Coverage Δ
3.10 74.76% <78.94%> (+0.07%) ⬆️
3.11 74.76% <78.94%> (+0.07%) ⬆️
3.8 74.61% <78.94%> (+0.07%) ⬆️
3.9 74.61% <78.94%> (+0.07%) ⬆️
integration 70.85% <78.94%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +68 to +70
execution_engine = datasource.get_execution_engine()
if isinstance(execution_engine, SqlAlchemyExecutionEngine):
execution_engine.close()
Copy link
Member

@Kilo59 Kilo59 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be enough to close all the sqlalchemy engine connections.
Some of our datasource use 2 different sqlalchemy engine instances.

Lets chat about this soon, but I think we need to add a datasource.close_connection()/datasource.shutdown_connection() method to the Datasource interface in OSS and let each datasource implement the respective close connection operation.

Copy link
Member Author

@anthonyburdi anthonyburdi Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. By two different engine instances do you mean the _engine_backup in the execution engine?

Copy link
Member

@Kilo59 Kilo59 Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I'm not familiar with _engine_backup; there could be an issue there too 😄 .

See the description of this abandoned PR.
But TLDR the SQLALchemy engine used in datasource.test_connection() is not the same engine used by the SQLAlchemyExecutionEngine.

As described 👇 this has been fixed for SnowflakeDatasource, but it's still a problem for Postgres, DatabricksSQL and every other SQL datasource.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. I did not know about the duplicate engine issue.
I also am realizing now that I missed that execution_engine.close() does not close the actual connection if the _engine_backup doesn't exist. I'm going to modify this PR to also explicitly call close on the connection just to test if it helps, but it sounds like we have more work to do overall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants