Skip to content

Commit b28375d

Browse files
authored
Merge pull request #1500 from likid1412/error_check
chore: cleanup error handling code
2 parents 73d42c4 + 59b26f7 commit b28375d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

bench/bench_reader/bench_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"bufio"
5+
"errors"
56
"flag"
67
"fmt"
78
"log"
89
"net"
910
"runtime"
10-
"strings"
1111
"sync"
1212
"sync/atomic"
1313
"time"
@@ -96,7 +96,7 @@ func subWorker(td time.Duration, workers int, tcpAddr string, topic string, chan
9696
for {
9797
resp, err := nsq.ReadResponse(rw)
9898
if err != nil {
99-
if strings.Contains(err.Error(), "use of closed network connection") {
99+
if errors.Is(err, net.ErrClosed) {
100100
break
101101
}
102102
panic(err.Error())

internal/http_api/http_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package http_api
22

33
import (
4+
"errors"
45
"fmt"
56
"log"
67
"net"
78
"net/http"
8-
"strings"
99

1010
"github.com/nsqio/nsq/internal/lg"
1111
)
@@ -28,7 +28,7 @@ func Serve(listener net.Listener, handler http.Handler, proto string, logf lg.Ap
2828
}
2929
err := server.Serve(listener)
3030
// theres no direct way to detect this error because it is not exposed
31-
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
31+
if err != nil && !errors.Is(err, net.ErrClosed) {
3232
return fmt.Errorf("http.Serve() error - %s", err)
3333
}
3434

internal/protocol/tcp_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package protocol
22

33
import (
4+
"errors"
45
"fmt"
56
"net"
67
"runtime"
7-
"strings"
88
"sync"
99

1010
"github.com/nsqio/nsq/internal/lg"
@@ -30,7 +30,7 @@ func TCPServer(listener net.Listener, handler TCPHandler, logf lg.AppLogFunc) er
3030
continue
3131
}
3232
// theres no direct way to detect this error because it is not exposed
33-
if !strings.Contains(err.Error(), "use of closed network connection") {
33+
if !errors.Is(err, net.ErrClosed) {
3434
return fmt.Errorf("listener.Accept() error - %s", err)
3535
}
3636
break

0 commit comments

Comments
 (0)