datarhei / gosrt

Implementation of the SRT protocol in pure Go
https://datarhei.com
MIT License
114 stars 17 forks source link

Rejected SRT request keeps getting accepted #59

Closed unext-wendong closed 2 months ago

unext-wendong commented 3 months ago

In the listener mode, it seems if the AcceptFunc returns REJECT, the same request will keep getting accepted, even though the incoming socket has gone.

The following sample code demonstrates the issue:

package main

import (
    "fmt"
    "time"

    srt "github.com/datarhei/gosrt"
)

func main() {
    conf := srt.DefaultConfig()
    ln, err := srt.Listen("srt", ":6000", conf)
    if err != nil {
        fmt.Println("err 1", err)
        return
    }

    for {
        fmt.Println("Accepting...")
        conn, mode, err := ln.Accept(func(req srt.ConnRequest) srt.ConnType {
            // check connection request
            fmt.Println("Got connection", req.RemoteAddr())
            time.Sleep(3 * time.Second)
            fmt.Println("Rejecting...")
            return srt.REJECT
        })
        if err != nil {
            fmt.Println("err 2", err)
            return
        }

        fmt.Println("conn", conn)
        if mode == srt.REJECT {
            // rejected connection, ignore
            continue
        }

        fmt.Println("mode", mode)
    }
}

Reproduce procedure:

  1. Start the listener.
  2. Use any SRT client to try to connect to the listener.
  3. Stop the SRT client once the listener starts accepting the request.
  4. Observe the listener behavior.

We observed the following output:

Accepting...
Got connection [::1]:65203
Rejecting...
conn <nil>
Accepting...
Got connection [::1]:65203
Rejecting...
conn <nil>
Accepting...
Got connection [::1]:65203
Rejecting...
conn <nil>
Accepting...
Got connection [::1]:65203
Rejecting...
conn <nil>
Accepting...
Got connection [::1]:65203
unext-wendong commented 3 months ago

From what I can tell, it's like it has gone to an endless loop. <-- Not accurate

Sorry, I shouldn't say "endless", it seems to be between 4 to around 12 times.