client: fix panic when writing packets after connection error (#681)

* Fix writer nullpointer panic on network reconnect

* add additional code and tests

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
Sijmen
2025-01-18 19:40:47 +01:00
committed by GitHub
parent 6240aa2847
commit b2cfa93d13
5 changed files with 44 additions and 23 deletions

View File

@@ -10,10 +10,11 @@ import (
type asyncProcessor struct {
bufferSize int
running bool
buffer *ringbuffer.RingBuffer
running bool
buffer *ringbuffer.RingBuffer
stopError error
chError chan error
stopped chan struct{}
}
func (w *asyncProcessor) initialize() {
@@ -22,22 +23,21 @@ func (w *asyncProcessor) initialize() {
func (w *asyncProcessor) start() {
w.running = true
w.chError = make(chan error)
w.stopped = make(chan struct{})
go w.run()
}
func (w *asyncProcessor) stop() {
if w.running {
w.buffer.Close()
<-w.chError
<-w.stopped
w.running = false
}
}
func (w *asyncProcessor) run() {
err := w.runInner()
w.chError <- err
close(w.chError)
w.stopError = w.runInner()
close(w.stopped)
}
func (w *asyncProcessor) runInner() error {