Skip to content

Commit

Permalink
Bugfix. Blocking on full queue in sub handler causes disconnect.
Browse files Browse the repository at this point in the history
If a client-side subscription channel is full, the 'Handle' RPC
call will hang indefinitely, ultimately causing the connection to
drop.  We fix this by making subscription handlers non-blocking,
ie.:  subscription messages are dropped if the consumer is not
receiving them fast enough.  This is consistent with the behavior
of libp2p-pubsub.
  • Loading branch information
lthibault committed Apr 22, 2022
1 parent 60f4561 commit e9a4cdd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/cap/pubsub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,16 @@ func (h handler) Shutdown() {
h.release()
}

func (h handler) Handle(ctx context.Context, call api.Topic_Handler_handle) error {
func (h handler) Handle(_ context.Context, call api.Topic_Handler_handle) error {
b, err := call.Args().Msg()
if err != nil {
return err
}

select {
case h.ms <- b:
return nil

case <-ctx.Done():
return ctx.Err()
default:
}

return nil
}

0 comments on commit e9a4cdd

Please sign in to comment.