run golangci-lint and apply suggested fixes
This commit is contained in:
@@ -13,6 +13,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint[:deadcode,unused]
|
||||
func debug(format string, args ...interface{}) {
|
||||
if debugEnabled {
|
||||
fmt.Fprintf(os.Stderr, "rpc/dataconn: %s\n", fmt.Sprintf(format, args...))
|
||||
|
||||
@@ -138,7 +138,6 @@ func (s *Server) serveConn(nc *transport.AuthConn) {
|
||||
default:
|
||||
s.log.WithField("endpoint", endpoint).Error("unknown endpoint")
|
||||
handlerErr = fmt.Errorf("requested endpoint does not exist")
|
||||
return
|
||||
}
|
||||
|
||||
s.log.WithField("endpoint", endpoint).WithField("errType", fmt.Sprintf("%T", handlerErr)).Debug("handler returned")
|
||||
@@ -188,6 +187,4 @@ func (s *Server) serveConn(nc *transport.AuthConn) {
|
||||
s.log.WithError(err).Error("cannot write send stream")
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package frameconn
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -48,7 +47,6 @@ func (f *FrameHeader) Unmarshal(buf []byte) {
|
||||
type Conn struct {
|
||||
readMtx, writeMtx sync.Mutex
|
||||
nc timeoutconn.Conn
|
||||
ncBuf *bufio.ReadWriter
|
||||
readNextValid bool
|
||||
readNext FrameHeader
|
||||
nextReadErr error
|
||||
|
||||
@@ -10,17 +10,11 @@ type shutdownFSM struct {
|
||||
type shutdownFSMState uint32
|
||||
|
||||
const (
|
||||
// zero value is important
|
||||
shutdownStateOpen shutdownFSMState = iota
|
||||
shutdownStateBegin
|
||||
)
|
||||
|
||||
func newShutdownFSM() *shutdownFSM {
|
||||
fsm := &shutdownFSM{
|
||||
state: shutdownStateOpen,
|
||||
}
|
||||
return fsm
|
||||
}
|
||||
|
||||
func (f *shutdownFSM) Begin() (thisCallStartedShutdown bool) {
|
||||
f.mtx.Lock()
|
||||
defer f.mtx.Unlock()
|
||||
|
||||
@@ -11,9 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type Conn struct {
|
||||
state state
|
||||
// if not nil, opErr is returned for ReadFrame and WriteFrame (not for Close, though)
|
||||
opErr atomic.Value // error
|
||||
state state
|
||||
fc *frameconn.Conn
|
||||
sendInterval, timeout time.Duration
|
||||
stopSend chan struct{}
|
||||
@@ -97,7 +95,10 @@ func (c *Conn) sendHeartbeats() {
|
||||
debug("send heartbeat")
|
||||
// if the connection is in zombie mode (aka iptables DROP inbetween peers)
|
||||
// this call or one of its successors will block after filling up the kernel tx buffer
|
||||
c.fc.WriteFrame([]byte{}, heartbeat)
|
||||
err := c.fc.WriteFrame([]byte{}, heartbeat)
|
||||
if err != nil {
|
||||
debug("send heartbeat error: %s", err)
|
||||
}
|
||||
// ignore errors from WriteFrame to rate-limit SendHeartbeat retries
|
||||
c.lastFrameSent.Store(time.Now())
|
||||
}()
|
||||
|
||||
@@ -13,6 +13,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint[:deadcode,unused]
|
||||
func debug(format string, args ...interface{}) {
|
||||
if debugEnabled {
|
||||
fmt.Fprintf(os.Stderr, "rpc/dataconn/heartbeatconn: %s\n", fmt.Sprintf(format, args...))
|
||||
|
||||
@@ -28,6 +28,7 @@ func WithLogger(ctx context.Context, log Logger) context.Context {
|
||||
return context.WithValue(ctx, contextKeyLogger, log)
|
||||
}
|
||||
|
||||
//nolint[:deadcode,unused]
|
||||
func getLog(ctx context.Context) Logger {
|
||||
log, ok := ctx.Value(contextKeyLogger).(Logger)
|
||||
if !ok {
|
||||
|
||||
@@ -23,9 +23,8 @@ type Conn struct {
|
||||
|
||||
// readMtx serializes read stream operations because we inherently only
|
||||
// support a single stream at a time over hc.
|
||||
readMtx sync.Mutex
|
||||
readClean bool
|
||||
allowWriteStreamTo bool
|
||||
readMtx sync.Mutex
|
||||
readClean bool
|
||||
|
||||
// writeMtx serializes write stream operations because we inherently only
|
||||
// support a single stream at a time over hc.
|
||||
@@ -95,7 +94,7 @@ func (c *Conn) ReadStreamedMessage(ctx context.Context, maxSize uint32, frameTyp
|
||||
}()
|
||||
err := readStream(c.frameReads, c.hc, w, frameType)
|
||||
c.readClean = isConnCleanAfterRead(err)
|
||||
w.CloseWithError(readMessageSentinel)
|
||||
_ = w.CloseWithError(readMessageSentinel) // always returns nil
|
||||
wg.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -166,7 +165,7 @@ func (c *Conn) SendStream(ctx context.Context, src zfs.StreamCopier, frameType u
|
||||
var res writeStreamRes
|
||||
res.errStream, res.errConn = writeStream(ctx, c.hc, r, frameType)
|
||||
if w != nil {
|
||||
w.CloseWithError(res.errStream)
|
||||
_ = w.CloseWithError(res.errStream) // always returns nil
|
||||
}
|
||||
writeStreamErrChan <- res
|
||||
}()
|
||||
|
||||
@@ -13,6 +13,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint[:deadcode,unused]
|
||||
func debug(format string, args ...interface{}) {
|
||||
if debugEnabled {
|
||||
fmt.Fprintf(os.Stderr, "rpc/dataconn/stream: %s\n", fmt.Sprintf(format, args...))
|
||||
|
||||
@@ -52,9 +52,6 @@ func (CloseWrite) sender(wire transport.Wire) {
|
||||
log.Printf("closeErr=%T %s", closeErr, closeErr)
|
||||
}()
|
||||
|
||||
type opResult struct {
|
||||
err error
|
||||
}
|
||||
writeDone := make(chan struct{}, 1)
|
||||
go func() {
|
||||
close(writeDone)
|
||||
|
||||
@@ -95,7 +95,7 @@ restart:
|
||||
return n, err
|
||||
}
|
||||
var nCurRead int
|
||||
nCurRead, err = c.Wire.Read(p[n:len(p)])
|
||||
nCurRead, err = c.Wire.Read(p[n:])
|
||||
n += nCurRead
|
||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && nCurRead > 0 {
|
||||
err = nil
|
||||
@@ -111,7 +111,7 @@ restart:
|
||||
return n, err
|
||||
}
|
||||
var nCurWrite int
|
||||
nCurWrite, err = c.Wire.Write(p[n:len(p)])
|
||||
nCurWrite, err = c.Wire.Write(p[n:])
|
||||
n += nCurWrite
|
||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && nCurWrite > 0 {
|
||||
err = nil
|
||||
|
||||
@@ -102,7 +102,7 @@ func TestNoPartialReadsDueToDeadline(t *testing.T) {
|
||||
// io.Copy will encounter a partial read, then wait ~50ms until the other 5 bytes are written
|
||||
// It is still going to fail with deadline err because it expects EOF
|
||||
n, err := io.Copy(&buf, bc)
|
||||
readDuration := time.Now().Sub(beginRead)
|
||||
readDuration := time.Since(beginRead)
|
||||
t.Logf("read duration=%s", readDuration)
|
||||
t.Logf("recv done n=%v err=%v", n, err)
|
||||
t.Logf("buf=%v", buf.Bytes())
|
||||
@@ -153,7 +153,7 @@ func TestPartialWriteMockConn(t *testing.T) {
|
||||
buf := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
begin := time.Now()
|
||||
n, err := mc.Write(buf[:])
|
||||
duration := time.Now().Sub(begin)
|
||||
duration := time.Since(begin)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 5, n)
|
||||
assert.True(t, duration > 100*time.Millisecond)
|
||||
|
||||
Reference in New Issue
Block a user