Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: DialTimeout leaks FD on Plan 9 #40118

Closed
fhs opened this issue Jul 8, 2020 · 1 comment
Closed

net: DialTimeout leaks FD on Plan 9 #40118

fhs opened this issue Jul 8, 2020 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Plan9

Comments

@fhs
Copy link
Contributor

fhs commented Jul 8, 2020

What version of Go are you using (go version)?

$ go version
go version devel +master Wed Jul 8 09:46:21 EDT 2020 plan9/amd64

What did you do?

Run:

package main

import (
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"strings"
	"sync"
	"time"
)

func fdCount() int {
	buf, err := ioutil.ReadFile(fmt.Sprintf("/proc/%v/fd", os.Getpid()))
	if err != nil {
		panic(err)
	}
	return strings.Count(string(buf), "/net/tcp/")
}

func main() {
	fmt.Printf("fd count before: %v\n", fdCount())

	var wg sync.WaitGroup
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			c, err := net.DialTimeout("tcp", "8.8.8.8:1234", 5*time.Second)
			if err != nil {
				fmt.Printf("%v\n", err)
				return
			}
			c.Close()
		}()
	}
	wg.Wait()

	fmt.Printf("fd count after: %v\n", fdCount())
	time.Sleep(time.Hour)
}

What did you expect to see?

fd count before: 0
dial 109728: warning: process exceeds 100 file descriptors
dial tcp 8.8.8.8:1234: i/o timeout
dial tcp 8.8.8.8:1234: i/o timeout
dial tcp 8.8.8.8:1234: i/o timeout
... (repeated 100 times)
fd count after: 0

What did you see instead?

fd count before: 0
dial 109728: warning: process exceeds 100 file descriptors
dial tcp 8.8.8.8:1234: i/o timeout
dial tcp 8.8.8.8:1234: i/o timeout
dial tcp 8.8.8.8:1234: i/o timeout
... (repeated 100 times)
fd count after: 100

The fds are for the control files (/net/tcp/clone) and netstat reports 100 connections to 8.8.8.8 on Syn_sent state. The dial function seems to be blocked on writing the connect control message. It eventually unblocks after normal TCP timeout (few minutes), but we should unblock it immediately by writing the hangup control message.

@gopherbot add labels OS-Plan9, NeedsFix

@gopherbot gopherbot added NeedsFix The path to resolution is known, but the work has not been done. OS-Plan9 labels Jul 8, 2020
@gopherbot
Copy link

Change https://golang.org/cl/241638 mentions this issue: net: hangup TCP connection after Dial timeout in Plan 9

@golang golang locked and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Plan9
Projects
None yet
Development

No branches or pull requests

2 participants