mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
check for uninitialized fields when closing the Transport (#3908)
* close Transport: check for possibly uninitialized fields * close Transport: close Conn, as conn might not be initialized * close Transport: add test case
This commit is contained in:
parent
9acce3c6d9
commit
8352e5dc32
2 changed files with 24 additions and 4 deletions
12
transport.go
12
transport.go
|
@ -244,14 +244,16 @@ func (t *Transport) runSendQueue() {
|
||||||
func (t *Transport) Close() error {
|
func (t *Transport) Close() error {
|
||||||
t.close(errors.New("closing"))
|
t.close(errors.New("closing"))
|
||||||
if t.createdConn {
|
if t.createdConn {
|
||||||
if err := t.conn.Close(); err != nil {
|
if err := t.Conn.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else if t.conn != nil {
|
||||||
t.conn.SetReadDeadline(time.Now())
|
t.conn.SetReadDeadline(time.Now())
|
||||||
defer func() { t.conn.SetReadDeadline(time.Time{}) }()
|
defer func() { t.conn.SetReadDeadline(time.Time{}) }()
|
||||||
}
|
}
|
||||||
<-t.listening // wait until listening returns
|
if t.listening != nil {
|
||||||
|
<-t.listening // wait until listening returns
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +282,9 @@ func (t *Transport) close(e error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t.handlerMap.Close(e)
|
if t.handlerMap != nil {
|
||||||
|
t.handlerMap.Close(e)
|
||||||
|
}
|
||||||
if t.server != nil {
|
if t.server != nil {
|
||||||
t.server.setCloseError(e)
|
t.server.setCloseError(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,4 +291,20 @@ var _ = Describe("Transport", func() {
|
||||||
close(packetChan)
|
close(packetChan)
|
||||||
tr.Close()
|
tr.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("closes uninitialized Transport and closes underlying PacketConn", func() {
|
||||||
|
packetChan := make(chan packetToRead)
|
||||||
|
pconn := newMockPacketConn(packetChan)
|
||||||
|
|
||||||
|
tr := &Transport{
|
||||||
|
Conn: pconn,
|
||||||
|
createdConn: true, // owns pconn
|
||||||
|
}
|
||||||
|
// NO init
|
||||||
|
|
||||||
|
// shutdown
|
||||||
|
close(packetChan)
|
||||||
|
pconn.EXPECT().Close()
|
||||||
|
Expect(tr.Close()).To(Succeed())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue