mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-02 22:52:33 -08:00
portlist: track churned listener by inode in TestPortlistBackendChurn
TestPortlistBackendChurn closed a fixture listener and then required the total number of listening ports in the network namespace to drop. That count covers every process sharing the namespace, so any other test package (testwrapper runs packages in parallel on CI) opening a socket between the two polls kept the count flat or raised it. The CI failures (before=12 after=12, before=11 after=11) were all on GitHub-hosted Linux runners, where only about a dozen sockets exist and any concurrent listener hides the removal. Checking the closed port number instead is not enough. Listings are deduplicated by proto and port, and tcp4 and tcp6 both report as "tcp", so another live socket with the same port number (an [::1] listener in this process, the first iteration's fixture, or another process) still shows up. Instrumenting a port-number check under flakestress recorded 30 such collisions in 11151 runs, each owned by another live socket and never by the closed listener. The backends themselves are fine: Close on a Go listener returns only after close(2), and the kernel unhashes a listening socket synchronously. So make the test fstat the listener to get its inode and check that the backend's li.known entry for that inode is present before the close and gone after it. flakestress -p 4 (concurrent copies share the netns): before: 5261 failures / 7066 runs (3m) port-number check: 5 failures / 9137 runs (8m) after (inode): 0 failures / 11151 runs (9m) Fixes #22348 Change-Id: Ie6699206b1de30d660ebb0092c1f5b421c23dc2c Signed-off-by: Brad Fitzpatrick <[email protected]>
This commit is contained in:
1 parent
1a4f4eb6ce
commit
f1bdb88ef1
1 file changed
+40
-18
@@ -14,6 +14,8 @@ import (
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// portFixture creates real sockets in the caller's network namespace. The
|
||||
@@ -319,26 +321,46 @@ func TestPortlistBackendChurn(t *testing.T) {
|
||||
if diag {
|
||||
requireDiag(t, li)
|
||||
}
|
||||
before, err := li.AppendListeningPorts(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
// Other sockets in this network namespace may share the closed
|
||||
// listener's port number or come and go concurrently, so track the
|
||||
// closed socket by inode rather than by port or total count.
|
||||
ln := f.listeners[0]
|
||||
key := socketInodeKey(t, ln.(*net.TCPListener))
|
||||
poll := func() []Port {
|
||||
t.Helper()
|
||||
ps, err := li.AppendListeningPorts(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diag && (li.diagFD < 0 || li.diagPermanent) {
|
||||
t.Fatal("diag churn poll fell back to proc")
|
||||
}
|
||||
return ps
|
||||
}
|
||||
if diag && (li.diagFD < 0 || li.diagPermanent) {
|
||||
t.Fatal("diag churn poll fell back to proc")
|
||||
if before := poll(); li.known[key] == nil {
|
||||
t.Fatalf("initial listing missing %s: %v", key, before)
|
||||
}
|
||||
if len(before) == 0 {
|
||||
t.Fatal("empty initial listing")
|
||||
}
|
||||
_ = f.listeners[0].Close()
|
||||
after, err := li.AppendListeningPorts(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diag && (li.diagFD < 0 || li.diagPermanent) {
|
||||
t.Fatal("diag churn poll fell back to proc")
|
||||
}
|
||||
if len(after) >= len(before) {
|
||||
t.Fatalf("churn did not remove listener: before=%d after=%d", len(before), len(after))
|
||||
_ = ln.Close()
|
||||
if after := poll(); li.known[key] != nil {
|
||||
t.Fatalf("churn did not remove listener %s: %v", key, after)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// socketInodeKey returns the li.known key for ln's socket.
|
||||
func socketInodeKey(t *testing.T, ln *net.TCPListener) string {
|
||||
t.Helper()
|
||||
rc, err := ln.SyscallConn()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var st unix.Stat_t
|
||||
var serr error
|
||||
if err := rc.Control(func(fd uintptr) { serr = unix.Fstat(int(fd), &st) }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if serr != nil {
|
||||
t.Fatal(serr)
|
||||
}
|
||||
return fmt.Sprintf("socket:[%d]", st.Ino)
|
||||
}
|
||||
Reference in new issue
Block a user