🐛 bug: make TLS listener config discovery safer#4055
Conversation
Summary of ChangesHello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the reliability and extensibility of TLS configuration discovery for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
WalkthroughRefactors TLS configuration retrieval in getTLSConfig to prefer interface-based access (TLSConfig()/Config()), adds defensive nil handling and guarded reflection fallback, removes an unused error variable, and adds tests covering diverse listener types. Changes
Sequence Diagram(s)(omitted — change is internal logic refactor without multi-component runtime interaction that benefits from a sequence diagram) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request significantly improves the safety and extensibility of TLS configuration discovery by introducing interface-based checks before falling back to a more robust reflection implementation. This change effectively prevents potential panics from the previous, more fragile approach. The added unit tests cover several important scenarios. My review includes a suggestion to simplify a small part of the new reflection logic and to add a test case for complete coverage of the new functionality. Overall, this is a solid improvement.
There was a problem hiding this comment.
Pull request overview
This PR improves the safety and extensibility of TLS configuration discovery for net.Listener implementations in the Fiber framework.
Changes:
- Refactored
getTLSConfig()function to use interface-based discovery before falling back to reflection - Added comprehensive test coverage for various listener types and TLS configuration scenarios
- Removed unused error constant that was previously used for panic conditions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| helpers.go | Refactored getTLSConfig() to check for TLSConfig() and Config() methods before using hardened reflection fallback |
| helpers_test.go | Added comprehensive unit tests covering standard TLS listeners, wrapped listeners, listeners with config methods, and non-TLS listeners |
| errors_internal.go | Removed unused errTLSConfigTypeAssertion constant that is no longer needed after removing panic behavior |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4055 +/- ##
==========================================
- Coverage 91.12% 91.09% -0.03%
==========================================
Files 119 119
Lines 11146 11166 +20
==========================================
+ Hits 10157 10172 +15
Misses 629 629
- Partials 360 365 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
net.Listenerimplementations without relying on fragile internal type names or panicking on unexpected types.Description
getTLSConfiginhelpers.goto prefer interface-based discovery by checking forTLSConfig() *tls.ConfigthenConfig() *tls.Configbefore falling back to reflection.reflect.Valuestates, field names, field types, and using safeInterface()/NewAtaccess only when appropriate, returningnilon any mismatch.Test_GetTLSConfiginhelpers_test.goexercising directtls.NewListener, wrapped listeners (without config methods), listeners exposingConfig() *tls.Config, and plain non-TLS listeners.errors_internal.gothat was previously used to panic.