Skip to content

Commit 8afce57

Browse files
gzliudan0g-wh
authored andcommitted
node: avoid double close resp.Body (ethereum#31710)
The functions `rpcRequest` and `batchRpcRequest` call `baseRpcRequest`. And `resp.Body` will be closed in the function `baseRpcRequest` later by `t.Cleanup`: ```go func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) *http.Response { // ...... t.Cleanup(func() { resp.Body.Close() }) return resp } ```
1 parent 320e8ca commit 8afce57

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

node/rpcstack_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ func TestHTTPWriteTimeout(t *testing.T) {
570570
// Send normal request
571571
t.Run("message", func(t *testing.T) {
572572
resp := rpcRequest(t, url, "test_sleep")
573-
defer resp.Body.Close()
574573
body, err := io.ReadAll(resp.Body)
575574
if err != nil {
576575
t.Fatal(err)
@@ -584,7 +583,6 @@ func TestHTTPWriteTimeout(t *testing.T) {
584583
t.Run("batch", func(t *testing.T) {
585584
want := fmt.Sprintf("[%s,%s,%s]", greetRes, timeoutRes, timeoutRes)
586585
resp := batchRpcRequest(t, url, []string{"test_greet", "test_sleep", "test_greet"})
587-
defer resp.Body.Close()
588586
body, err := io.ReadAll(resp.Body)
589587
if err != nil {
590588
t.Fatal(err)

0 commit comments

Comments
 (0)