Skip to content

proposal: cmd/vet: warn about copying a time.Timer value #69186

Open
@tulir

Description

@tulir

The following code works fine on Go 1.22, but breaks on Go 1.23.0 on the http.DefaultClient.Do() line. On Linux, it freezes the entire runtime and never continues. On macOS, it throws a fatal error: ts set in timer

package main

import (
	"fmt"
	"net/http"
	"time"
)

func main() {
	illegalTimerCopy := *time.NewTimer(10 * time.Second)
	go func() {
		illegalTimerCopy.Reset(10 * time.Second)
	}()
	req, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
	fmt.Println("Request created", err)
	_, err = http.DefaultClient.Do(req)
	fmt.Println("Request completed", err)
}

It's presumably somehow caused by the Go 1.23 timer changes, but I'm not sure how exactly, so I don't know if it's a bug or a feature. Assuming it's not a bug, it would be nice if go vet could report that similar to the mutex copy warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions