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

@@ -626,9 +626,9 @@ func (ss *ServerSession) run() {
func (ss *ServerSession) runInner() error {
for {
chWriterError := func() chan error {
if ss.writer != nil {
return ss.writer.chError
chWriterError := func() chan struct{} {
if ss.writer != nil && ss.writer.running {
return ss.writer.stopped
}
return nil
}()
@@ -729,8 +729,8 @@ func (ss *ServerSession) runInner() error {
ss.udpCheckStreamTimer = time.NewTimer(ss.s.checkStreamPeriod)
case err := <-chWriterError:
return err
case <-chWriterError:
return ss.writer.stopError
case <-ss.ctx.Done():
return liberrors.ErrServerTerminated{}
@@ -1306,7 +1306,6 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
}
ss.writer.stop()
ss.writer = nil
ss.timeDecoder = nil