Skip to content

eventbus: dont panic on closing Subscription twice - #3034

Merged
sukunrt merged 1 commit into
masterfrom
sukun/sub-close-multiple
Nov 13, 2024
Merged

sukunrt merged 1 commit into
masterfrom
sukun/sub-close-multiple

Conversation

@sukunrt

@sukunrt sukunrt commented Nov 11, 2024 •

Copy link
Copy Markdown
Member

fixes: #3002

@sukunrt
sukunrt requested a review from MarcoPolo November 11, 2024 15:22
@MarcoPolo

Copy link
Copy Markdown
Collaborator

I'm not sure. Why wouldn't this follow the same semantics as closing a channel twice? https://play.golang.com/p/S5frqwAAI1j. That panics, and this seems similar to me.

@sukunrt

sukunrt commented Nov 12, 2024 •

Copy link
Copy Markdown
Member Author

Not a fan of that decision either.

Channel closing twice panics so that it explicitly disallows broken concurrency primitives and avoids race conditions with multiple senders closing the channel.

In our case, there's no way to synchronize a subscriber with an emitter. In fact, when dealing with channels, the receiver never closes a channel, it's always the sender who closes the channel because otherwise the sender might panic. Here the subscriber closes the channel.

Plus, In almost all cases, the subscriber is closed at the end of the object life time. It seems fine to close it twice with the second one being a no op just like calling Close on a stream twice isn't a panic.

@MarcoPolo MarcoPolo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not convinced by the argument, but I really don't like panics.

@sukunrt

sukunrt commented Nov 13, 2024

Copy link
Copy Markdown
Member Author

I don't like them either!

@sukunrt
sukunrt merged commit 7268c98 into master Nov 13, 2024
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.

Issue panic when user interrupt signal

2 participants