From bc7052ace71e2b040514b948b8db6c535f26176b Mon Sep 17 00:00:00 2001 From: rkonfj Date: Wed, 7 Aug 2024 21:00:18 +0800 Subject: [PATCH] deadline: close conn should return io.EOF --- connmux/connmux.go | 9 +++++++-- p2p/conn.go | 6 +++++- rdt/rdt.go | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/connmux/connmux.go b/connmux/connmux.go index 5e84539..7697107 100644 --- a/connmux/connmux.go +++ b/connmux/connmux.go @@ -81,7 +81,10 @@ func (c *MuxConn) Read(b []byte) (n int, err error) { select { case <-c.exit: return 0, io.EOF - case <-c.deadlineRead.Deadline(): + case _, ok := <-c.deadlineRead.Deadline(): + if !ok { + return 0, io.EOF + } return 0, N.ErrDeadline case wsb, ok := <-c.inbound: if !ok { @@ -308,8 +311,10 @@ func (l *MuxSession) nextFrame() error { delete(l.dials, seq) slog.Debug("ClientSideMuxConnClosed", "seq", c.seq) } + default: + return fmt.Errorf("unsupport connmux cmd %d", cmd) } - return fmt.Errorf("unsupport connmux cmd %d", cmd) + return nil } func (d *MuxSession) OpenStream() (net.Conn, error) { diff --git a/p2p/conn.go b/p2p/conn.go index bfd2f84..c90ca6d 100644 --- a/p2p/conn.go +++ b/p2p/conn.go @@ -53,7 +53,11 @@ func (c *PeerPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) { case <-c.closedSig: err = net.ErrClosed return - case <-c.deadlineRead.Deadline(): + case _, ok := <-c.deadlineRead.Deadline(): + if !ok { + err = net.ErrClosed + return + } err = N.ErrDeadline return case datagram := <-c.wsConn.Datagrams(): diff --git a/rdt/rdt.go b/rdt/rdt.go index 1de310a..4420b33 100644 --- a/rdt/rdt.go +++ b/rdt/rdt.go @@ -72,7 +72,10 @@ func (c *rdtConn) Read(b []byte) (n int, err error) { case <-c.exit: err = io.EOF return - case <-c.deadlineRead.Deadline(): + case _, ok := <-c.deadlineRead.Deadline(): + if !ok { + return 0, io.EOF + } err = N.ErrDeadline return case pkt, ok := <-c.inbound: