Skip to content

Commit 45447b4

Browse files
committed
net/http: use runtime.AddCleanup instead of runtime.SetFinalizer
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>
1 parent 85f8e24 commit 45447b4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/net/http/clientserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ func testTransportGCRequest(t *testing.T, mode testMode, body bool) {
12531253
(func() {
12541254
body := strings.NewReader("some body")
12551255
req, _ := NewRequest("POST", cst.ts.URL, body)
1256-
runtime.SetFinalizer(req, func(*Request) { close(didGC) })
1256+
runtime.AddCleanup(req, func(ch chan struct{}) { close(ch) }, didGC)
12571257
res, err := cst.c.Do(req)
12581258
if err != nil {
12591259
t.Fatal(err)

src/net/http/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ func (d *countingDialer) DialContext(ctx context.Context, network, address strin
20342034
d.total++
20352035
d.live++
20362036

2037-
runtime.SetFinalizer(counted, d.decrement)
2037+
runtime.AddCleanup(counted, func(dd *countingDialer) { dd.decrement(nil) }, d)
20382038
return counted, nil
20392039
}
20402040

@@ -2106,7 +2106,7 @@ func (cc *contextCounter) Track(ctx context.Context) context.Context {
21062106
cc.mu.Lock()
21072107
defer cc.mu.Unlock()
21082108
cc.live++
2109-
runtime.SetFinalizer(counted, cc.decrement)
2109+
runtime.AddCleanup(counted, func(c *contextCounter) { cc.decrement(nil) }, cc)
21102110
return counted
21112111
}
21122112

0 commit comments

Comments
 (0)