renproject / aw

A flexible P2P networking library for upgradable distributed systems.
MIT License
38 stars 18 forks source link

Receive functions not registered properly when having more than one receiver. #60

Closed tok-kkk closed 3 years ago

tok-kkk commented 3 years ago

Inside the channel package, the client.Receive() function won't register receiver functions if you call it more than once. Calls after the first one will just exit and does nothing (since the client.receiversRunning has been marked to true)

I'm thinking to add

        select {
        case <-ctx.Done():
        case client.receivers <- receiver{ctx: ctx, f: f}:
        }

between https://github.com/renproject/aw/blob/27ccfc3bf6e42e58328bafc71802d139da40f6a3/channel/client.go#L171-L172 but I realize it could cause a potential deadlock.

I'll let you guys decide how to fix this.

loongy commented 3 years ago

The only reason this condition is here is to ensure that the Goroutine is only spawned once. So it should be fine to add the suggested select statement between L172 and L173. This avoids the deadlock issue.

rahulghangas commented 3 years ago

Fixed as part of PR 56

jazg commented 3 years ago

@rahulghangas Sweet! It would be good to have some regression tests for that if you haven't already added some.