From 80bf639aea51863b915a6bf46dfb13bd601fd844 Mon Sep 17 00:00:00 2001 From: Kleissner Date: Mon, 8 Nov 2021 05:12:40 +0100 Subject: [PATCH] UDT: Provide io.EOF signal in udtSocket.fetchReadPacket. Otherwise readers may linger forever. --- udt/udtsocket.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/udt/udtsocket.go b/udt/udtsocket.go index c7924fc..49e4733 100644 --- a/udt/udtsocket.go +++ b/udt/udtsocket.go @@ -2,6 +2,7 @@ package udt import ( "errors" + "io" "net" "sync" "syscall" @@ -141,6 +142,9 @@ func (s *udtSocket) fetchReadPacket(blocking bool) ([]byte, error) { } select { case result = <-s.messageIn: + if result == nil { // nil result indicates EOF + return nil, io.EOF + } return result, nil case _, ok := <-deadline: if !ok { @@ -159,6 +163,9 @@ func (s *udtSocket) fetchReadPacket(blocking bool) ([]byte, error) { // ok we've read some stuff and there's nothing immediately available return nil, nil } + if result == nil { // nil result indicates EOF. Using this instead of socket state allows to drain any buffered data first. + return nil, io.EOF + } return result, nil }