incubator-seata-go icon indicating copy to clipboard operation
incubator-seata-go copied to clipboard

bugfix: fix connection leaks and potential nil pointer panic(#991)

Open HGD-coder opened this issue 1 month ago • 3 comments

What this PR does:

  • Fixed connection leak in pkg/datasource/sql/datasource/base/meta_cache.go by adding defer conn.Close()
  • Fixed connection leak in pkg/datasource/sql/db.go by adding defer conn.Close()
  • Added proper error handling in pkg/datasource/sql/async_worker.go to prevent nil pointer panic when db.Conn() fails

Which issue(s) this PR fixes:

Fixes #991

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

HGD-coder avatar Nov 23 '25 09:11 HGD-coder

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.

HGD-coder avatar Nov 24 '25 11:11 HGD-coder

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.

codecov-commenter avatar Nov 25 '25 12:11 codecov-commenter