Skip to content

Commit

Permalink
cleanup error handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
likid1412 committed Oct 25, 2024
1 parent 4de1606 commit 59b26f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bench/bench_reader/bench_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"bufio"
"errors"
"flag"
"fmt"
"log"
"net"
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -96,7 +96,7 @@ func subWorker(td time.Duration, workers int, tcpAddr string, topic string, chan
for {
resp, err := nsq.ReadResponse(rw)
if err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {
if errors.Is(err, net.ErrClosed) {
break
}
panic(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions internal/http_api/http_server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package http_api

import (
"errors"
"fmt"
"log"
"net"
"net/http"
"strings"

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

Expand Down
4 changes: 2 additions & 2 deletions internal/protocol/tcp_server.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package protocol

import (
"errors"
"fmt"
"net"
"runtime"
"strings"
"sync"

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

0 comments on commit 59b26f7

Please sign in to comment.