bugfix: fix connection leaks and potential nil pointer panic(#991)
What this PR does:
- Fixed connection leak in
pkg/datasource/sql/datasource/base/meta_cache.goby addingdefer conn.Close() - Fixed connection leak in
pkg/datasource/sql/db.goby addingdefer conn.Close() - Added proper error handling in
pkg/datasource/sql/async_worker.goto prevent nil pointer panic whendb.Conn()fails
Which issue(s) this PR fixes:
Fixes #991
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
NONE
The previous test code used db: &sql.DB{} to create a database object. This is an incomplete instance where essential internal fields (like the driverConn) are nil. When the code under test attempts to call the conn.Close() method, it causes the program to crash (a panic) due to a nil pointer dereference.
Codecov Report
:x: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 56.34%. Comparing base (b90d3ae) to head (273b9f7).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| pkg/datasource/sql/async_worker.go | 0.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #997 +/- ##
==========================================
- Coverage 56.37% 56.34% -0.04%
==========================================
Files 266 266
Lines 17480 17484 +4
==========================================
- Hits 9855 9851 -4
- Misses 6794 6799 +5
- Partials 831 834 +3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.