]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: use runtime.AddCleanup instead of runtime.SetFinalizer
authorCarlos Amedee <carlos@golang.org>
Tue, 11 Feb 2025 20:50:55 +0000 (15:50 -0500)
committerCarlos Amedee <carlos@golang.org>
Fri, 14 Feb 2025 17:59:55 +0000 (09:59 -0800)
Replace the usage of runtime.SetFinalizer with runtime.AddCleanup in
tests.

Updates #70907

Change-Id: Idd3f1c07f6a7709352ca09948fbcb4a0ad9418bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/648655
Auto-Submit: Carlos Amedee <carlos@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/net/http/clientserver_test.go
src/net/http/transport_test.go

index 32d97ea9f083ce3094d2edf52fc4d8d613001b18..208c6509fac75892fabbecc785173b105b883e0c 100644 (file)
@@ -1253,7 +1253,7 @@ func testTransportGCRequest(t *testing.T, mode testMode, body bool) {
        (func() {
                body := strings.NewReader("some body")
                req, _ := NewRequest("POST", cst.ts.URL, body)
-               runtime.SetFinalizer(req, func(*Request) { close(didGC) })
+               runtime.AddCleanup(req, func(ch chan struct{}) { close(ch) }, didGC)
                res, err := cst.c.Do(req)
                if err != nil {
                        t.Fatal(err)
index a454db5e034ff03120cd7a67219c83fdfa89d583..7166c11279233426deb85b084c8cce741115f179 100644 (file)
@@ -2034,7 +2034,7 @@ func (d *countingDialer) DialContext(ctx context.Context, network, address strin
        d.total++
        d.live++
 
-       runtime.SetFinalizer(counted, d.decrement)
+       runtime.AddCleanup(counted, func(dd *countingDialer) { dd.decrement(nil) }, d)
        return counted, nil
 }
 
@@ -2106,7 +2106,7 @@ func (cc *contextCounter) Track(ctx context.Context) context.Context {
        cc.mu.Lock()
        defer cc.mu.Unlock()
        cc.live++
-       runtime.SetFinalizer(counted, cc.decrement)
+       runtime.AddCleanup(counted, func(c *contextCounter) { cc.decrement(nil) }, cc)
        return counted
 }