apache / dubbo-getty

a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Apache License 2.0
220 stars 69 forks source link

Bug: maybe can not read the last tcp package #77

Closed AlexStocks closed 2 years ago

AlexStocks commented 2 years ago

What happened: image image

image image

when read the last tcp package,the return value of Read is "pkgLen, eof". So we should process the last package before considering the error.

However, getty just handle the error and then exit without processing the last package.

What you expected to happen:

Getty processes the last the package before handling the error.

AlexStocks commented 2 years ago

as internal/poll/fd_posix.go fd.eofError shows, when got eof error, the tcp stream buffer length is zero. So this issue is not valid.

What's more, even if the return value "len != 0, error == eof", we will get "len == 0, error == eof" if we continue to read the closed socket as the following examples.

  1. firstly, we start a nc tcp server.
nc -lk 127.0.0.1 20000
  1. start a go client.
package main

import (
        "log"
        "net"
        "os"
        "time"
)

func main() {
    conn, err := net.Dial("tcp", "127.0.0.1:20000")
    if err != nil {
        log.Println("dial failed:", err)
        os.Exit(1)
    }
    defer conn.Close()

    buffer := make([]byte, 512)
    for {
        conn.SetReadDeadline(time.Now().Add(1 * time.Second))
        n, err := conn.Read(buffer)
        if err != nil {
            log.Println("Read failed, error:", err, ", count: ", n)
            // return
        } else {
            log.Println("count:", n, "msg:", string(buffer))
        }

        time.Sleep(3e9)
    }
}
  1. After start the go client successfully, close the nc tcp server.
  2. The output of the go tcp client is as follows.

image