Skip to content

Commit

Permalink
Fixes unregistering a channel on a possibly closed stream data broadc…
Browse files Browse the repository at this point in the history
…aster
  • Loading branch information
mpiraux committed Mar 15, 2022
1 parent 383f75d commit 36255f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion agents/http3_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ func (a *HTTP3Agent) SendRequest(path, method, authority string, headers map[str
a.responseBuffer[streamID] = response

go func() { // Pipes the data from the response stream to the agent
defer stream.ReadChan.Unregister(streamChan)
defer func() {
if !stream.ReadChan.IsClosed() {
stream.ReadChan.Unregister(streamChan)
}
}()
for {
select {
case i := <-streamChan:
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/dustin/go-broadcast"
type Broadcaster struct {
broadcast.Broadcaster
channels []chan interface{}
isClosed bool
}

func NewBroadcaster(buflen int) Broadcaster {
Expand All @@ -19,8 +20,15 @@ func (b *Broadcaster) RegisterNewChan(size int) chan interface{} {
}

func (b *Broadcaster) Close() error {
if b.isClosed {
return nil
}
b.isClosed = true
for _, c := range b.channels {
close(c)
}
return b.Broadcaster.Close()
}
func (b *Broadcaster) IsClosed() bool {
return b.isClosed
}

0 comments on commit 36255f1

Please sign in to comment.