fix(producer): prevent panic when TraceDispatcher is a typed nil #1232
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.
PR Title
[ISSUE #1231 ] Fix panic caused by typed nil TraceDispatcher in producer
What is the purpose of the change
This pull request fixes a potential panic during the producer initialization when a "typed nil" is passed as a
TraceDispatcher.In Go, an interface holding a nil concrete pointer is not equal to
nil. The previous checkif dispatcher != nilfailed to detect this scenario. If a user passes a typed nil (e.g., a nil pointer of a concrete struct implementing the interface), the check passes, but the subsequent call todispatcher.Start()triggers a panic on the nil receiver.To resolve this, I added a reflection-based check
!reflect.ValueOf(dispatcher).IsNil()to ensure the underlying value is strictly not nil before proceeding.Brief changelog
reflect.ValueOf(dispatcher).IsNil()check innewTraceInterceptorto prevent initialization with typed nils.TestNewTraceInterceptor_WithTypedNilto verify that passing a typed nil does not cause a panic.Verifying this change
The change is verified by a new unit test case that explicitly constructs a typed nil interface and passes it to the interceptor.
go test ./producer/...TestNewTraceInterceptor_WithTypedNilpasses and no panic occurs.Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.[ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.