fix: add actionable guidance for TLS handshake failures in Go 1.23+/1.25+#356
Open
dlevy-msft-sql wants to merge 7 commits into
Open
fix: add actionable guidance for TLS handshake failures in Go 1.23+/1.25+#356dlevy-msft-sql wants to merge 7 commits into
dlevy-msft-sql wants to merge 7 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #356 +/- ##
===========================================
+ Coverage 80.66% 96.62% +15.95%
===========================================
Files 35 92 +57
Lines 6842 74379 +67537
===========================================
+ Hits 5519 71865 +66346
- Misses 1055 2177 +1122
- Partials 268 337 +69
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
15dc192 to
1785b05
Compare
….25+ Wraps TLS handshake errors with GODEBUG hints when Go rejects SHA-1 certificates or negative serial numbers. Uses case-insensitive matching for SHA-1 error detection across Go versions.
1785b05 to
dc54c9d
Compare
There was a problem hiding this comment.
Pull request overview
Improves the driver’s TLS handshake failure diagnostics by wrapping handshake errors with actionable guidance (including relevant GODEBUG workarounds) for known Go crypto/tls policy changes, helping users self-remediate certificate-related failures.
Changes:
- Add
wrapTLSError()intds.goto recognize specific TLS/cert failure strings and append remediation guidance. - Apply the wrapper at both TLS handshake sites (
getTLSConn()and the standard encryption path inconnect()), ensuring proper error wrapping (%w). - Add unit tests covering the known patterns and default behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tds.go | Introduces wrapTLSError() and uses it at both TLS handshake call sites to enrich errors with guidance. |
| tds_unit_test.go | Adds unit tests validating wrapping behavior, message contents, and errors.Is unwrapping. |
- Change wrapTLSError to require both 'cannot read handshake' AND 'eof' instead of matching either independently. Prevents false SHA-1 guidance for unrelated network errors. - Add server-side conn.SetDeadline in TestConnectNonStrictTLSHandshakeError to prevent goroutine hangs. - Reduce TestGetTLSConnHandshakeError timeout from 5s to 1s. - Replace raw DSN string with net/url builder for proper parameter encoding. - Add test case verifying handshake-without-EOF falls to default wrapper.
silverwind
pushed a commit
to go-gitea/gitea
that referenced
this pull request
May 27, 2026
The following TLS handshake error is fixed by newer versions of mssql (refer to microsoft/mssql-docker#895 (comment)) ``` TLS Handshake failed: tls: failed to parse certificate from server: x509: negative serial number ``` Based on microsoft/go-sqlcmd#755 (comment), newer versions of mssql don't have this problem. And there're changes going to mssql driver side to make this error more explicit microsoft/go-mssqldb#356. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wraps TLS handshake errors with specific GODEBUG workaround instructions when Go's
crypto/tlsrejects server certificates due to policy changes in newer Go versions.Problem
Users hitting TLS handshake failures get opaque error messages with no guidance on how to resolve them:
Changes
wrapTLSError()helper intds.gothat pattern-matches known TLS error strings and appends actionable workaround text (specificGODEBUGenvironment variable settings)getTLSConn()(strict/TDS8 path) andconnect()(standard encryption path)%winstead of%vfor proper error wrappingWhat this does NOT do
Example error messages
Before:
After:
Closes #302, closes #217, closes #231