Skip to content

Commit

Permalink
ignore TLS handshake error
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jan 26, 2024
1 parent 05246c2 commit 8068fd1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
15 changes: 10 additions & 5 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,11 @@ func (cr *Cluster) CheckFiles(dir string, files []FileInfo, heavy bool) (missing
checkThrCount int
checkResCh chan *FileInfo
disabled = cr.Disabled()
pollCheckSlot func()
pollCheckSlot func() bool
)
if heavy {
checkResCh = make(chan *FileInfo, 16)
pollCheckSlot = func() {
pollCheckSlot = func() bool {
if checkThrCount >= checkSlotLimit {
select {
case f := <-checkResCh:
Expand All @@ -602,11 +602,12 @@ func (cr *Cluster) CheckFiles(dir string, files []FileInfo, heavy bool) (missing
}
case <-disabled:
logWarn("File check interrupted")
return nil
return true
}
} else {
checkThrCount++
}
return false
}
}

Expand All @@ -622,7 +623,9 @@ func (cr *Cluster) CheckFiles(dir string, files []FileInfo, heavy bool) (missing
continue
}
if heavy {
pollCheckSlot()
if pollCheckSlot() {
return nil
}
go func(f FileInfo) {
var missing *FileInfo = nil
defer func() {
Expand Down Expand Up @@ -662,7 +665,9 @@ func (cr *Cluster) CheckFiles(dir string, files []FileInfo, heavy bool) (missing
p += ".gz"
if _, err := os.Stat(p); err == nil {
if heavy {
pollCheckSlot()
if pollCheckSlot() {
return nil
}
go func(f FileInfo) {
var missing *FileInfo = nil
defer func() {
Expand Down
3 changes: 3 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -140,3 +141,5 @@ func startFlushLogFile() {
}
}()
}

var NullLogger = log.New(DevNull, "", log.LstdFlags)
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ START:
ReadTimeout: 10 * time.Second,
IdleTimeout: 5 * time.Second,
Handler: cluster.GetHandler(),
ErrorLog: NullLogger, // for ignore TLS handshake error
}

go func(ctx context.Context) {
Expand Down
16 changes: 9 additions & 7 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,20 @@ func copyFile(src, dst string, mode os.FileMode) (err error) {
return
}

type nullReader struct{}
type devNull struct{}

var (
NullReader = nullReader{}
DevNull = devNull{}

_ io.ReaderAt = NullReader
_ io.ReadSeeker = NullReader
_ io.ReaderAt = DevNull
_ io.ReadSeeker = DevNull
_ io.Writer = DevNull
)

func (nullReader) Read([]byte) (int, error) { return 0, io.EOF }
func (nullReader) ReadAt([]byte, int64) (int, error) { return 0, io.EOF }
func (nullReader) Seek(int64, int) (int64, error) { return 0, nil }
func (devNull) Read([]byte) (int, error) { return 0, io.EOF }
func (devNull) ReadAt([]byte, int64) (int, error) { return 0, io.EOF }
func (devNull) Seek(int64, int) (int64, error) { return 0, nil }
func (devNull) Write(buf []byte) (int, error) { return len(buf), nil }

var errNotSeeker = errors.New("r is not an io.Seeker")

Expand Down

0 comments on commit 8068fd1

Please sign in to comment.