Skip to content

event: make nil available#34915

Open
cuiweixie wants to merge 1 commit into
ethereum:masterfrom
cuiweixie:nil-bug
Open

event: make nil available#34915
cuiweixie wants to merge 1 commit into
ethereum:masterfrom
cuiweixie:nil-bug

Conversation

@cuiweixie

@cuiweixie cuiweixie commented May 9, 2026

Copy link
Copy Markdown
Contributor

Description
Problem

When FeedOf is instantiated with an interface-shaped type argument (notably any / interface{}) and callers use Send(nil), the logical value is nil carried inside an interface box. Taking reflect.ValueOf(value) in that situation yields an invalid reflect.Value, because the boxed value does not expose a concrete type the way reflect expects.

That invalidated value was then plugged into reflective send helpers (reflect.SelectCase, reflect.Value.TrySend). The old behaviour was wrong in practice: Send(nil) could panic or fail to deliver, instead of broadcasting nil to subscribers like any other payload.

Fix

Build the reflect.Value used for sending from reflect.ValueOf(&value).Elem(), so the holder of T is reflected correctly and the send path sees a valid value (including “nil interface” cases).

Testing

Add TestFeedOfSendNilAnySucceeds, which subscribes two buffered channels on a FeedOf[any], calls Send(nil), and asserts nsent == 2 and that both subscribers receive nil. This locks in the fixed behaviour and documents the previous failure mode.

@cuiweixie cuiweixie requested a review from fjl as a code owner May 9, 2026 13:45
@fjl

fjl commented May 9, 2026

Copy link
Copy Markdown
Contributor

Please give justification for this change!

@cuiweixie

Copy link
Copy Markdown
Contributor Author

Please give justification for this change!

Done

@fjl fjl self-assigned this May 10, 2026
Comment thread event/feedof.go Outdated
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.

2 participants