mirror of
https://github.com/LBRYFoundation/reflector.go.git
synced 2025-08-23 17:27:25 +00:00
consolidate errors that happen a lot and we know about
This commit is contained in:
parent
d7a4b34d8c
commit
473e7e3b07
2 changed files with 17 additions and 4 deletions
|
@ -155,8 +155,10 @@ func (s *Server) handleConn(conn net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) doError(conn net.Conn, err error) error {
|
func (s *Server) doError(conn net.Conn, err error) error {
|
||||||
log.Errorln(errors.FullTrace(err))
|
shouldLog := s.stats.AddError(err)
|
||||||
s.stats.AddError(err)
|
if shouldLog {
|
||||||
|
log.Errorln(errors.FullTrace(err))
|
||||||
|
}
|
||||||
if e2, ok := err.(*json.SyntaxError); ok {
|
if e2, ok := err.(*json.SyntaxError); ok {
|
||||||
log.Errorf("syntax error at byte offset %d", e2.Offset)
|
log.Errorf("syntax error at byte offset %d", e2.Offset)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package reflector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -54,14 +55,24 @@ func (s *stats) AddStream() {
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.streams += 1
|
s.streams += 1
|
||||||
}
|
}
|
||||||
func (s *stats) AddError(e error) {
|
|
||||||
|
func (s *stats) AddError(e error) (shouldLog bool) { // shouldLog is a hack, but whataever
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := errors.Wrap(e, 0)
|
err := errors.Wrap(e, 0)
|
||||||
|
name := err.TypeName()
|
||||||
|
if strings.Contains(err.Error(), "i/o timeout") {
|
||||||
|
name = "i/o timeout"
|
||||||
|
} else if strings.Contains(err.Error(), "read: connection reset by peer") {
|
||||||
|
name = "read conn reset"
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldLog = true
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.errors[err.TypeName()] += 1
|
s.errors[name] += 1
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stats) runSlackLogger() {
|
func (s *stats) runSlackLogger() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue