server: fix panic due to regression in #887 (#892)

This happened when writing a TCP packet to a conn after a read error.
This commit is contained in:
Alessandro Ros
2025-09-16 10:36:06 +02:00
committed by GitHub
parent 3f446ed08d
commit 8c7e4320bc
7 changed files with 69 additions and 42 deletions

View File

@@ -12,9 +12,16 @@ type clientReader struct {
mutex sync.Mutex
allowInterleavedFrames bool
terminate chan struct{}
done chan struct{}
}
func (r *clientReader) start() {
r.terminate = make(chan struct{})
r.done = make(chan struct{})
go r.run()
}
@@ -24,19 +31,20 @@ func (r *clientReader) setAllowInterleavedFrames(v bool) {
r.allowInterleavedFrames = v
}
func (r *clientReader) wait() {
for {
select {
case <-r.c.chResponse:
case <-r.c.chRequest:
case <-r.c.chReadError:
return
}
}
func (r *clientReader) close() {
close(r.terminate)
<-r.done
}
func (r *clientReader) run() {
r.c.chReadError <- r.runInner()
defer close(r.done)
err := r.runInner()
select {
case r.c.chReadError <- err:
case <-r.terminate:
}
}
func (r *clientReader) runInner() error {
@@ -48,10 +56,16 @@ func (r *clientReader) runInner() error {
switch what := what.(type) {
case *base.Response:
r.c.chResponse <- what
select {
case r.c.chResponse <- what:
case <-r.terminate:
}
case *base.Request:
r.c.chRequest <- what
select {
case r.c.chRequest <- what:
case <-r.terminate:
}
case *base.InterleavedFrame:
r.mutex.Lock()