I figured it out. Because the subscribe channel is buffered. Technically the broker can see the unsubscribe for the client before the subscribe message. So it closes the channel then tries to send on it. 

On Mar 4, 2025, at 8:23 AM, cpu...@gmail.com <cpui...@gmail.com> wrote:

Thanks Robert,

with unbuffered channels it doesn't panic- but the play also doesn't end. Debugger confirms "all go routines asleep" (not sure why).
I'd also still be confused why the (un)subscribe channels should matter. As long as (in unsubscribe) the msgCh hasn't been removed it can still be sent to, buffering wouldn't change that.

Thanks for your interest in chasing this :)

Cheers,
Andi
On Tuesday, March 4, 2025 at 3:09:11 PM UTC+1 Robert Engels wrote:
Actually all if the channels need to be unbuffered. Otherwise you have pending data that isn’t read when the channel is closed. When I make them all unbuffered it works. 

On Mar 4, 2025, at 8:04 AM, cpu...@gmail.com <cpu...@gmail.com> wrote:

Thanks Robert,

did a quick try and still panics. This seems to make sense- the unsubscribe is the root cause of the panic- while it's still in the buffer the channel won't be closed.

Cheers,
Andi

On Tuesday, March 4, 2025 at 3:01:37 PM UTC+1 Robert Engels wrote:
You can’t make the unsubscribe channel buffered. 

On Mar 4, 2025, at 7:55 AM, cpu...@gmail.com <cpu...@gmail.com> wrote:

Thanks Jan, but this just confirms that there is a send on a closed channel. 

It makes me wonder though (far, very far shot): given the map of subscriptions is using the new swissmap, might that be a bug with that? As I've said- very long shot.

Cheers,
Andi

On Tuesday, March 4, 2025 at 2:51:41 PM UTC+1 Jan Mercl wrote:
On Tue, Mar 4, 2025 at 2:41 PM cpu...@gmail.com <cpu...@gmail.com> wrote:

> I've recently run across https://stackoverflow.com/questions/36417199/how-to-broadcast-message-using-channel by icza and tried to use the simple broker in my project.
>
> Unfortunately, it panics with send on closed channel. I couldn't figure out why or where and created a reproducer: https://play.golang.com/p/8hrHf4-nGY2
>
> Can someone spot why this would panic (except for the obvious reason) and how to fix it?

I didn't analyze the code, but maybe this can help:
https://play.golang.com/p/Ix003aXFFul

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/c1a2ed5f-6b94-4acc-8d8f-465131e74651n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/bc94988b-63b6-43f0-8db0-ad3b1cef8e67n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/35290341-8D6C-436E-A70B-0B3ADDEA8D96%40ix.netcom.com.

Reply via email to