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

Fix io.Closer support for connectors #199

Merged
merged 4 commits into from
Dec 15, 2023

Conversation

begelundmuller
Copy link
Contributor

It appears that closing a DB using XSAM/otelsql does not always propagate to the underlying driver. That's apparently due to io.Closer being optional for connectors and database/sql using a type assertion to check whether the connector implements it. That type assertion does not pass through to otConnector.Connector, so we need to explicitly implement Close() error on otConnector and replicate the type assertion there.

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (359c955) 80.5% compared to head (566e458) 80.7%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #199     +/-   ##
=======================================
+ Coverage   80.5%   80.7%   +0.1%     
=======================================
  Files         13      13             
  Lines        716     723      +7     
=======================================
+ Hits         577     584      +7     
  Misses       115     115             
  Partials      24      24             

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

Copy link
Owner

@XSAM XSAM left a comment

Choose a reason for hiding this comment

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

Hi @begelundmuller, thanks for raising this PR. It looks good.

Please also update the CHANGELOG.md to reflect this fix.

func (c *otConnector) Close() error {
// database/sql uses a type assertion to check if connectors implement io.Closer.
// The type assertion does not pass through to otConnector.Connector, so we explicitly implement it here.
if closer, ok := c.Connector.(io.Closer); ok {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please add an implement assertion in line 26 to show otConnector implements io.Closer?
https://github.com/XSAM/otelsql/pull/199/files#diff-c1caa8de39e277339469495d65efd1a363c54065c3cc02e7422b097774e56c86R25
It should be

var _ io.Closer = (*otConnector)(nil)

@begelundmuller
Copy link
Contributor Author

@XSAM thanks for the rapid review! I have addressed both of your comments.

@XSAM
Copy link
Owner

XSAM commented Dec 13, 2023

@begelundmuller Thanks for your contribution.

Please update this branch with the base branch.

@begelundmuller
Copy link
Contributor Author

begelundmuller commented Dec 14, 2023

Please update this branch with the base branch.

Done!

@XSAM XSAM merged commit c5d14ef into XSAM:main Dec 15, 2023
16 checks passed
@XSAM XSAM mentioned this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants