Skip to content

testing: fuzzing failed to run if test run with open TCP connections #71560

@shuLhan

Description

@shuLhan

Go version

go version devel go1.25-cc874072f3 Mon Feb 3 08:25:31 2025 -0800 linux/amd64

Output of go env in your module/workspace:

AR='ar'                                                                                                                 
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/ms/go/bin'
GOCACHE='/home/ms/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ms/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2786547649=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/ms/src/go/src/go.mod'
GOMODCACHE='/home/ms/go/pkg/mod'
GONOPROXY='<REDACTED>'
GONOSUMDB='<REDACTED>'
GOOS='linux'
GOPATH='/home/ms/go'
GOPRIVATE='<REDACTED>'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/ms/local/share/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/ms/.config/go/telemetry'
GOTMPDIR=''

What did you do?

Given the following code and fuzzing test based on Fuzzing tutorial [1]

package main

import (
	"fmt"
	"html"
	"log"
	"net"
	"net/http"
	"testing"
	"unicode/utf8"
)

func FuzzReverse(f *testing.F) {
	// Uncomment either runHTTPServer or runTCPServer to make test fuzz
	// fail.
	go runHTTPServer()
	//go runTCPServer()
	testcases := []string{"Hello, world", " ", "!12345"}
	for _, tc := range testcases {
		f.Add(tc) // Use f.Add to provide a seed corpus
	}
	f.Fuzz(func(t *testing.T, orig string) {
		rev, err1 := Reverse(orig)
		if err1 != nil {
			return
		}
		doubleRev, err2 := Reverse(rev)
		if err2 != nil {
			return
		}
		if orig != doubleRev {
			t.Errorf("Before: %q, after: %q", orig, doubleRev)
		}
		if utf8.ValidString(orig) && !utf8.ValidString(rev) {
			t.Errorf("Reverse produced invalid UTF-8 string %q", rev)
		}
	})
}

func runHTTPServer() {
	http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
	})

	log.Fatal(http.ListenAndServe(":18080", nil))
}

func runTCPServer() {
	ln, err := net.Listen("tcp", ":18081")
	if err != nil {
		log.Fatal(`runTCPServer:`, err)
	}
	for {
		_, err := ln.Accept()
		if err != nil {
			log.Fatal(`runTCPServer: Accept`, err)
		}
	}
}

I believe the same issues has been reported several times,

There are other issues but I am not sure if its related,

The only error that I can trace is there is a broken pipe during ping [2].

[1] https://go.dev/doc/tutorial/fuzz
[2]

if err := w.client.ping(ctx); err != nil {

What did you see happen?

The fuzz process terminated with an error EOF,

$ go test -fuzz=. -run=none -fuzztime=10s -v
=== RUN   FuzzReverse
fuzz: elapsed: 0s, gathering baseline coverage: 0/46 completed
fuzz: elapsed: 0s, gathering baseline coverage: 0/46 completed
--- FAIL: FuzzReverse (0.02s)
    fuzzing process terminated without fuzzing: EOF
=== NAME  
FAIL
exit status 1
FAIL    git.sr.ht/~shulhan/sandbox.go/fuzz      0.021s

What did you expect to see?

Uncomment both of the lines in FuzzReverse,

	//go runHTTPServer()
	//go runTCPServer()

and run the test again,

$ go test -fuzz=. -run=none -fuzztime=10s -v                                                                      
=== RUN   FuzzReverse                                                                                                   
fuzz: elapsed: 0s, gathering baseline coverage: 0/46 completed
fuzz: elapsed: 0s, gathering baseline coverage: 46/46 completed, now fuzzing with 4 workers
fuzz: elapsed: 3s, execs: 130236 (43416/sec), new interesting: 0 (total: 46)
fuzz: elapsed: 6s, execs: 255613 (41785/sec), new interesting: 0 (total: 46)
fuzz: elapsed: 9s, execs: 387455 (43941/sec), new interesting: 0 (total: 46)
fuzz: elapsed: 10s, execs: 431389 (40198/sec), new interesting: 0 (total: 46)
--- PASS: FuzzReverse (10.10s) 
=== NAME  
PASS
ok      git.sr.ht/~shulhan/sandbox.go/fuzz      10.107s

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions