upgrade go-ident

Fixes a socket leak (that doesn't seem to be affecting tilde.town?)
This commit is contained in:
Shivaram Lingamneni 2023-09-12 01:39:49 -04:00
parent 2013beb7c8
commit 3bd3c6a88a
4 changed files with 15 additions and 8 deletions

View file

@ -38,6 +38,12 @@ func (e ProtocolError) Error() string {
// Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds.
func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) {
// if a timeout is set, respect it from the beginning of the query, including the dial time
var deadline time.Time
if timeout > 0 {
deadline = time.Now().Add(timeout)
}
var conn net.Conn
if timeout > 0 {
conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout)
@ -47,13 +53,12 @@ func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (re
if err != nil {
return
}
defer conn.Close()
// stop the ident read after <timeout> seconds
if timeout > 0 {
conn.SetDeadline(time.Now().Add(timeout))
}
// if timeout is 0, `deadline` is the empty time.Time{} which means no deadline:
conn.SetDeadline(deadline)
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n"))
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d\r\n", portOnClient, portOnServer)))
if err != nil {
return
}

4
vendor/modules.txt vendored
View file

@ -13,8 +13,8 @@ github.com/docopt/docopt-go
# github.com/ergochat/confusables v0.0.0-20201108231250-4ab98ab61fb1
## explicit
github.com/ergochat/confusables
# github.com/ergochat/go-ident v0.0.0-20200511222032-830550b1d775
## explicit
# github.com/ergochat/go-ident v0.0.0-20230911071154-8c30606d6881
## explicit; go 1.18
github.com/ergochat/go-ident
# github.com/ergochat/irc-go v0.4.0
## explicit; go 1.15