Skip to content

fix: stop AttributesFromDSN panicking on unix-socket DSNs#625

Open
SAY-5 wants to merge 1 commit intoXSAM:mainfrom
SAY-5:fix/attributes-from-dsn-unix-socket-panic-624
Open

fix: stop AttributesFromDSN panicking on unix-socket DSNs#625
SAY-5 wants to merge 1 commit intoXSAM:mainfrom
SAY-5:fix/attributes-from-dsn-unix-socket-panic-624

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 20, 2026

Fixes #624.

AttributesFromDSN first split the DSN on the first / to drop the database/params suffix, and then unwrapped any protocol(addr) form by taking dsn[openParen+1 : len(dsn)-1]. That ordering is safe for most addresses but breaks as soon as the address itself contains a slash:

unix(/tmp/mysql.sock)/mysql?parseTime=true

The / split happens inside the parentheses, truncating dsn to unix(. The protocol unwrap then computes [openParen+1 : len(dsn)-1] = [5:4], which panics with slice bounds out of range.

This PR extracts the protocol(addr) address first by reading between the matching parens, and only falls back to the first-/ trim on bare addresses. That makes the unix-socket case round-trip to semconv.ServerAddress("/tmp/mysql.sock") and leaves every existing test case unchanged. A regression test is added for the unix-socket DSN.

AttributesFromDSN first split the DSN on the first '/' to drop the
database/params suffix, and then unwrapped any protocol(addr) form by
taking dsn[openParen+1 : len(dsn)-1]. That ordering is safe for most
addresses but breaks as soon as the address itself contains a slash:

    unix(/tmp/mysql.sock)/mysql?parseTime=true

The '/' split happens inside the parentheses, truncating dsn to
`unix(`. The protocol unwrap then computes [openParen+1 : len(dsn)-1]
= [5:4], which panics with slice bounds out of range (XSAM#624).

Extract the protocol(addr) address first by reading between the
matching parens, and only fall back to the first-'/' trim on bare
addresses. This makes the unix-socket case round-trip to
semconv.ServerAddress("/tmp/mysql.sock") and leaves every
existing test case unchanged.

Fixes XSAM#624
@SAY-5 SAY-5 requested a review from XSAM as a code owner April 20, 2026 07:03
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.4%. Comparing base (31f7989) to head (6f8e3fd).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #625   +/-   ##
=====================================
  Coverage   86.4%   86.4%           
=====================================
  Files         16      16           
  Lines        752     752           
=====================================
  Hits         650     650           
  Misses        75      75           
  Partials      27      27           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Panics with unix domain socket DSN

1 participant