From de33ab2b2163deb89c3837e071cbe5258625c736 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Mon, 6 Jan 2025 14:58:42 -0500 Subject: [PATCH 1/5] Add revive linter to golangci-lint --- .golangci.yml | 2 ++ rpc/client.go | 4 ++-- rpc/connection.go | 4 ++-- rpc/connection_test.go | 10 +++++----- rpc/connection_test_util.go | 16 ++++++++-------- rpc/context.go | 28 ++++++++++++++-------------- rpc/context_test.go | 12 ++++++------ rpc/dispatch.go | 10 +++++----- rpc/dispatch_test.go | 14 +++++++------- rpc/errors.go | 10 +++++----- rpc/instrument.go | 4 ++-- rpc/log.go | 15 ++++++--------- rpc/log_test_util.go | 2 +- rpc/message.go | 16 ++++++++-------- rpc/message_test.go | 4 ++-- rpc/packetizer_test.go | 8 ++++---- rpc/protocol_test.go | 8 ++++---- rpc/protocol_utils_test.go | 12 ++++++------ rpc/receiver_test.go | 2 +- rpc/request.go | 4 ++-- rpc/resinit/resinit.go | 2 +- 21 files changed, 93 insertions(+), 94 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 23aaf43..e467d8c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,5 +7,7 @@ linters-settings: linters: enable: - gofmt + - govet - gocritic - unconvert + - revive diff --git a/rpc/client.go b/rpc/client.go index 34ef581..f582358 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -70,13 +70,13 @@ func (c *Client) call(ctx context.Context, method string, if c.tagsFunc != nil { tags, ok := c.tagsFunc(ctx) if ok { - rpcTags := make(CtxRpcTags) + rpcTags := make(CtxRPCTags) for key, tagName := range tags { if v := ctx.Value(key); v != nil { rpcTags[tagName] = v } } - ctx = AddRpcTagsToContext(ctx, rpcTags) + ctx = AddRPCTagsToContext(ctx, rpcTags) } } diff --git a/rpc/connection.go b/rpc/connection.go index fbb5763..4caf318 100644 --- a/rpc/connection.go +++ b/rpc/connection.go @@ -119,7 +119,7 @@ func (t *connTransport) Dial(ctx context.Context) (Transporter, error) { // https://github.com/rust-lang/rust/blob/028569ab1b/src/libstd/sys_common/net.rs#L186-L190 // Note that we still propagate the error here, and we expect callers // to retry. - resinit.ResInitIfDNSError(err) + resinit.IfDNSError(err) return nil, err } @@ -274,7 +274,7 @@ func (ct *ConnectionTransportTLS) Dial(ctx context.Context) ( // https://github.com/rust-lang/rust/blob/028569ab1b/src/libstd/sys_common/net.rs#L186-L190 // Note that we still propagate the error here, and we expect // callers to retry. - resinit.ResInitIfDNSError(err) + resinit.IfDNSError(err) return nil, err } ct.log.Debug("baseConn: %s; Calling %s", diff --git a/rpc/connection_test.go b/rpc/connection_test.go index 7ed6680..f6e9b2d 100644 --- a/rpc/connection_test.go +++ b/rpc/connection_test.go @@ -49,12 +49,12 @@ func (ut *unitTester) OnDisconnected(context.Context, DisconnectStatus) { } // ShouldRetry implements the ConnectionHandler interface. -func (ut *unitTester) ShouldRetry(name string, err error) bool { +func (ut *unitTester) ShouldRetry(_ string, err error) bool { _, isThrottle := err.(throttleError) return isThrottle } -var errCanceled = errors.New("Canceled!") +var errCanceled = errors.New("canceled") // ShouldRetryOnConnect implements the ConnectionHandler interface. func (ut *unitTester) ShouldRetryOnConnect(err error) bool { @@ -62,7 +62,7 @@ func (ut *unitTester) ShouldRetryOnConnect(err error) bool { } // Dial implements the ConnectionTransport interface. -func (ut *unitTester) Dial(ctx context.Context) ( +func (ut *unitTester) Dial(_ context.Context) ( Transporter, error) { if ut.alwaysFail || ut.numConnectErrors == 0 { return nil, ut.errToThrow @@ -338,13 +338,13 @@ type mockedDialable struct { setoptsWasCalled bool } -func (md *mockedDialable) SetOpts(timeout time.Duration, keepAlive time.Duration) { +func (md *mockedDialable) SetOpts(_ time.Duration, _ time.Duration) { md.mutex.Lock() md.setoptsWasCalled = true md.mutex.Unlock() } -func (md *mockedDialable) Dial(ctx context.Context, network string, addr string) (net.Conn, error) { +func (md *mockedDialable) Dial(_ context.Context, _ string, _ string) (net.Conn, error) { md.mutex.Lock() md.dialWasCalled = true md.mutex.Unlock() diff --git a/rpc/connection_test_util.go b/rpc/connection_test_util.go index 58afbb7..6aaa6b2 100644 --- a/rpc/connection_test_util.go +++ b/rpc/connection_test_util.go @@ -17,20 +17,20 @@ func (testConnectionHandler) OnConnect(context.Context, *Connection, GenericClie return nil } -func (testConnectionHandler) OnConnectError(err error, reconnectThrottleDuration time.Duration) { +func (testConnectionHandler) OnConnectError(_ error, _ time.Duration) { } -func (testConnectionHandler) OnDoCommandError(err error, nextTime time.Duration) { +func (testConnectionHandler) OnDoCommandError(_ error, _ time.Duration) { } -func (testConnectionHandler) OnDisconnected(ctx context.Context, status DisconnectStatus) { +func (testConnectionHandler) OnDisconnected(_ context.Context, _ DisconnectStatus) { } -func (testConnectionHandler) ShouldRetry(name string, err error) bool { +func (testConnectionHandler) ShouldRetry(_ string, _ error) bool { return false } -func (testConnectionHandler) ShouldRetryOnConnect(err error) bool { +func (testConnectionHandler) ShouldRetryOnConnect(_ error) bool { return false } @@ -45,7 +45,7 @@ type singleTransport struct { var _ ConnectionTransport = singleTransport{} // Dial is an implementation of the ConnectionTransport interface. -func (st singleTransport) Dial(ctx context.Context) (Transporter, error) { +func (st singleTransport) Dial(_ context.Context) (Transporter, error) { if !st.t.IsConnected() { return nil, io.EOF } @@ -67,11 +67,11 @@ type testStatus struct { Code int } -func testWrapError(err error) interface{} { +func testWrapError(_ error) interface{} { return &testStatus{} } -func testLogTags(ctx context.Context) (map[interface{}]string, bool) { +func testLogTags(_ context.Context) (map[interface{}]string, bool) { return nil, false } diff --git a/rpc/context.go b/rpc/context.go index ace1756..2d4fd45 100644 --- a/rpc/context.go +++ b/rpc/context.go @@ -2,36 +2,36 @@ package rpc import "golang.org/x/net/context" -// CtxRpcKey is a type defining the context key for the RPC context -type CtxRpcKey int +// CtxRPCKey is a type defining the context key for the RPC context +type CtxRPCKey int const ( - // CtxRpcTagsKey defines a context key that can hold a slice of context keys - CtxRpcTagsKey CtxRpcKey = iota + // CtxRPCTagsKey defines a context key that can hold a slice of context keys + CtxRPCTagsKey CtxRPCKey = iota ) -type CtxRpcTags map[string]interface{} +type CtxRPCTags map[string]interface{} -// AddRpcTagsToContext adds the given log tag mappings (logTagsToAdd) to the +// AddRPCTagsToContext adds the given log tag mappings (logTagsToAdd) to the // given context, creating a new one if necessary. Returns the resulting // context with the new log tag mappings. -func AddRpcTagsToContext(ctx context.Context, logTagsToAdd CtxRpcTags) context.Context { - currTags, ok := RpcTagsFromContext(ctx) +func AddRPCTagsToContext(ctx context.Context, logTagsToAdd CtxRPCTags) context.Context { + currTags, ok := TagsFromContext(ctx) if !ok { - currTags = make(CtxRpcTags) + currTags = make(CtxRPCTags) } for key, tag := range logTagsToAdd { currTags[key] = tag } - return context.WithValue(ctx, CtxRpcTagsKey, currTags) + return context.WithValue(ctx, CtxRPCTagsKey, currTags) } -// RpcTagsFromContext returns the tags being passed along with the given context. -func RpcTagsFromContext(ctx context.Context) (CtxRpcTags, bool) { - logTags, ok := ctx.Value(CtxRpcTagsKey).(CtxRpcTags) +// TagsFromContext returns the tags being passed along with the given context. +func TagsFromContext(ctx context.Context) (CtxRPCTags, bool) { + logTags, ok := ctx.Value(CtxRPCTagsKey).(CtxRPCTags) if ok { - ret := make(CtxRpcTags) + ret := make(CtxRPCTags) for k, v := range logTags { ret[k] = v } diff --git a/rpc/context_test.go b/rpc/context_test.go index c389e35..b499c39 100644 --- a/rpc/context_test.go +++ b/rpc/context_test.go @@ -8,21 +8,21 @@ import ( ) func TestRpcTags(t *testing.T) { - logTags := make(CtxRpcTags) + logTags := make(CtxRPCTags) logTags["hello"] = "world" logTags["foo"] = "bar" - ctx := AddRpcTagsToContext(context.Background(), logTags) + ctx := AddRPCTagsToContext(context.Background(), logTags) - logTags2 := make(CtxRpcTags) + logTags2 := make(CtxRPCTags) logTags2["hello"] = "world2" - ctx = AddRpcTagsToContext(ctx, logTags2) + ctx = AddRPCTagsToContext(ctx, logTags2) - logTags, _ = RpcTagsFromContext(ctx) + logTags, _ = TagsFromContext(ctx) require.Equal(t, "world2", logTags["hello"]) require.Equal(t, "bar", logTags["foo"]) - outTags, ok := RpcTagsFromContext(ctx) + outTags, ok := TagsFromContext(ctx) require.Equal(t, true, ok) require.Equal(t, logTags, outTags) diff --git a/rpc/dispatch.go b/rpc/dispatch.go index 11daed5..2c6ef59 100644 --- a/rpc/dispatch.go +++ b/rpc/dispatch.go @@ -62,7 +62,7 @@ func (d *dispatch) Call(ctx context.Context, name string, arg interface{}, res i method = MethodCallCompressed } - record := NewNetworkInstrumenter(d.instrumenterStorage, RPCInstrumentTag(method, name)) + record := NewNetworkInstrumenter(d.instrumenterStorage, InstrumentTag(method, name)) c := d.calls.NewCall(ctx, name, arg, res, ctype, u, record) // Have to add call before encoding otherwise we'll race the response @@ -84,7 +84,7 @@ func (d *dispatch) Call(ctx context.Context, name string, arg interface{}, res i logCall = func() { d.log.ClientCallCompressed(c.seqid, c.method, c.arg, c.ctype) } } - rpcTags, _ := RpcTagsFromContext(ctx) + rpcTags, _ := TagsFromContext(ctx) if len(rpcTags) > 0 { v = append(v, rpcTags) } @@ -118,14 +118,14 @@ func (d *dispatch) Call(ctx context.Context, name string, arg interface{}, res i } func (d *dispatch) Notify(ctx context.Context, name string, arg interface{}, sendNotifier SendNotifier) error { - rpcTags, _ := RpcTagsFromContext(ctx) + rpcTags, _ := TagsFromContext(ctx) v := []interface{}{MethodNotify, name, arg} if len(rpcTags) > 0 { v = append(v, rpcTags) } size, errCh := d.writer.EncodeAndWrite(ctx, v, currySendNotifier(sendNotifier, SeqNumber(-1))) - record := NewNetworkInstrumenter(d.instrumenterStorage, RPCInstrumentTag(MethodNotify, name)) + record := NewNetworkInstrumenter(d.instrumenterStorage, InstrumentTag(MethodNotify, name)) defer func() { _ = record.RecordAndFinish(ctx, size) }() select { @@ -149,7 +149,7 @@ func (d *dispatch) Close() { func (d *dispatch) handleCancel(ctx context.Context, c *call) error { d.log.ClientCancel(c.seqid, c.method, nil) size, errCh := d.writer.EncodeAndWriteAsync([]interface{}{MethodCancel, c.seqid, c.method}) - record := NewNetworkInstrumenter(d.instrumenterStorage, RPCInstrumentTag(MethodCancel, c.method)) + record := NewNetworkInstrumenter(d.instrumenterStorage, InstrumentTag(MethodCancel, c.method)) defer func() { _ = record.RecordAndFinish(ctx, size) }() select { case err := <-errCh: diff --git a/rpc/dispatch_test.go b/rpc/dispatch_test.go index 1f674a7..7699243 100644 --- a/rpc/dispatch_test.go +++ b/rpc/dispatch_test.go @@ -9,7 +9,7 @@ import ( "golang.org/x/net/context" ) -func dispatchTestCallWithContextAndCompressionType(t *testing.T, ctx context.Context, ctype CompressionType) (dispatcher, *callContainer, chan error) { +func dispatchTestCallWithContextAndCompressionType(ctx context.Context, t *testing.T, ctype CompressionType) (dispatcher, *callContainer, chan error) { log := newTestLog(t) instrumenterStorage := NewMemoryInstrumentationStorage() @@ -33,12 +33,12 @@ func dispatchTestCallWithContextAndCompressionType(t *testing.T, ctx context.Con return d, calls, done } -func dispatchTestCallWithContext(t *testing.T, ctx context.Context) (dispatcher, *callContainer, chan error) { - return dispatchTestCallWithContextAndCompressionType(t, ctx, CompressionNone) +func dispatchTestCallWithContext(ctx context.Context, t *testing.T) (dispatcher, *callContainer, chan error) { + return dispatchTestCallWithContextAndCompressionType(ctx, t, CompressionNone) } func dispatchTestCall(t *testing.T) (dispatcher, *callContainer, chan error) { - return dispatchTestCallWithContext(t, context.Background()) + return dispatchTestCallWithContext(context.Background(), t) } func sendResponse(c *call, err error) { @@ -63,7 +63,7 @@ func TestDispatchSuccessfulCall(t *testing.T) { func TestDispatchSuccessfulCallCompressed(t *testing.T) { doWithAllCompressionTypes(func(ctype CompressionType) { - d, calls, done := dispatchTestCallWithContextAndCompressionType(t, context.Background(), ctype) + d, calls, done := dispatchTestCallWithContextAndCompressionType(context.Background(), t, ctype) c := calls.RetrieveCall(0) require.NotNil(t, c, "Expected c not to be nil") @@ -79,7 +79,7 @@ func TestDispatchSuccessfulCallCompressed(t *testing.T) { func TestDispatchCanceledBeforeResult(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - d, calls, done := dispatchTestCallWithContext(t, ctx) + d, calls, done := dispatchTestCallWithContext(ctx, t) c := calls.RetrieveCall(0) require.NotNil(t, c, "Expected c not to be nil") @@ -102,7 +102,7 @@ func TestDispatchCanceledBeforeResult(t *testing.T) { func TestDispatchCanceledAfterResult(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) - d, calls, done := dispatchTestCallWithContext(t, ctx) + d, calls, done := dispatchTestCallWithContext(ctx, t) c := calls.RetrieveCall(0) require.NotNil(t, c, "Expected c not to be nil") diff --git a/rpc/errors.go b/rpc/errors.go index 3d46945..ee0fb44 100644 --- a/rpc/errors.go +++ b/rpc/errors.go @@ -112,7 +112,7 @@ func (c NilResultError) Error() string { return fmt.Sprintf("Nil result supplied for sequence number %d", c.seqno) } -type RPCDecodeError struct { +type DecodeError struct { err error typ MethodType len int @@ -120,12 +120,12 @@ type RPCDecodeError struct { ctype CompressionType } -func (r RPCDecodeError) Error() string { +func (r DecodeError) Error() string { return fmt.Sprintf("RPC error. type: %s, method: %s, length: %d, compression: %v, error: %v", r.typ, r.name, r.len, r.ctype, r.err) } -func newRPCDecodeError(t MethodType, n string, l int, ctype CompressionType, err error) RPCDecodeError { - return RPCDecodeError{ +func newRPCDecodeError(t MethodType, n string, l int, ctype CompressionType, err error) DecodeError { + return DecodeError{ err: err, typ: t, len: l, @@ -140,7 +140,7 @@ func newRPCMessageFieldDecodeError(i int, err error) error { func unboxRPCError(err error) error { switch e := err.(type) { - case RPCDecodeError: + case DecodeError: return e.err default: return err diff --git a/rpc/instrument.go b/rpc/instrument.go index 6931efd..9b2d992 100644 --- a/rpc/instrument.go +++ b/rpc/instrument.go @@ -13,7 +13,7 @@ type NetworkInstrumenterStorage interface { Put(ctx context.Context, tag string, record InstrumentationRecord) error } -func RPCInstrumentTag(methodType MethodType, method string) string { +func InstrumentTag(methodType MethodType, method string) string { return fmt.Sprintf("%s %s", methodType, method) } @@ -48,7 +48,7 @@ func NewMemoryInstrumentationStorage() *MemoryInstrumentationStorage { } } -func (s *MemoryInstrumentationStorage) Put(ctx context.Context, tag string, record InstrumentationRecord) error { +func (s *MemoryInstrumentationStorage) Put(_ context.Context, tag string, record InstrumentationRecord) error { s.Lock() defer s.Unlock() s.storage[tag] = append(s.storage[tag], record) diff --git a/rpc/log.go b/rpc/log.go index 796c4e7..1006edc 100644 --- a/rpc/log.go +++ b/rpc/log.go @@ -164,14 +164,12 @@ func (s SimpleLogFactory) NewLog(a net.Addr) LogInterface { func AddrToString(addr net.Addr) string { if addr == nil { return "-" - } else { - c := addr.String() - if len(c) == 0 { - return addr.Network() - } else { - return addr.Network() + "://" + c - } } + c := addr.String() + if len(c) == 0 { + return addr.Network() + } + return addr.Network() + "://" + c } func (s SimpleLog) TransportStart() { @@ -306,9 +304,8 @@ func (s SimpleLog) StartProfiler(format string, args ...interface{}) Profiler { msg: fmt.Sprintf(format, args...), log: s, } - } else { - return NilProfiler{} } + return NilProfiler{} } func (s SimpleLog) UnexpectedReply(seqno SeqNumber) { diff --git a/rpc/log_test_util.go b/rpc/log_test_util.go index c257398..b80cd61 100644 --- a/rpc/log_test_util.go +++ b/rpc/log_test_util.go @@ -43,7 +43,7 @@ func (t *testLogOutput) Profile(fmt string, args ...interface{}) { t.log("P", fmt, args) } -func (t *testLogOutput) CloneWithAddedDepth(depth int) LogOutputWithDepthAdder { return t } +func (t *testLogOutput) CloneWithAddedDepth(_ int) LogOutputWithDepthAdder { return t } func newTestLog(t TestLogger) SimpleLog { log := testLogOutput{t: t} diff --git a/rpc/message.go b/rpc/message.go index 29b7ed9..15807d2 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -36,11 +36,11 @@ func (r *basicRPCData) loadContext(l int, d *fieldDecoder) error { if l == 0 { return nil } - tags := make(CtxRpcTags) + tags := make(CtxRPCTags) if err := d.Decode(&tags); err != nil { return err } - r.ctx = AddRpcTagsToContext(context.Background(), tags) + r.ctx = AddRPCTagsToContext(context.Background(), tags) return nil } @@ -68,7 +68,7 @@ func (r *rpcCallMessage) DecodeMessage(l int, d *fieldDecoder, p *protocolHandle if r.err = d.Decode(&r.name); r.err != nil { return r.err } - r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, RPCInstrumentTag(r.Type(), r.Name())) + r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, InstrumentTag(r.Type(), r.Name())) r.instrumenter.IncrementSize(int64(d.totalSize)) if r.arg, r.err = p.getArg(r.name); r.err != nil { return r.err @@ -128,7 +128,7 @@ func (r *rpcCallCompressedMessage) DecodeMessage(l int, d *fieldDecoder, p *prot if r.err = d.Decode(&r.name); r.err != nil { return r.err } - r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, RPCInstrumentTag(r.Type(), r.Name())) + r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, InstrumentTag(r.Type(), r.Name())) r.instrumenter.IncrementSize(int64(d.totalSize)) if r.arg, r.err = p.getArg(r.name); r.err != nil { return r.err @@ -184,7 +184,7 @@ func (r *rpcResponseMessage) RecordAndFinish(ctx context.Context, size int64) er return r.c.instrumenter.RecordAndFinish(ctx, size) } -func (r *rpcResponseMessage) DecodeMessage(l int, d *fieldDecoder, _ *protocolHandler, cc *callContainer, +func (r *rpcResponseMessage) DecodeMessage(_ int, d *fieldDecoder, _ *protocolHandler, cc *callContainer, compressorCacher *compressorCacher, _ NetworkInstrumenterStorage) error { var seqNo SeqNumber @@ -315,7 +315,7 @@ func (r *rpcNotifyMessage) DecodeMessage(l int, d *fieldDecoder, p *protocolHand if r.err = d.Decode(&r.name); r.err != nil { return r.err } - r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, RPCInstrumentTag(r.Type(), r.Name())) + r.instrumenter = NewNetworkInstrumenter(instrumenterStorage, InstrumentTag(r.Type(), r.Name())) r.instrumenter.IncrementSize(int64(d.totalSize)) if r.arg, r.err = p.getArg(r.name); r.err != nil { return r.err @@ -361,11 +361,11 @@ type rpcCancelMessage struct { err error } -func (r *rpcCancelMessage) RecordAndFinish(ctx context.Context, size int64) error { +func (r *rpcCancelMessage) RecordAndFinish(_ context.Context, _ int64) error { return nil } -func (r *rpcCancelMessage) DecodeMessage(l int, d *fieldDecoder, p *protocolHandler, _ *callContainer, +func (r *rpcCancelMessage) DecodeMessage(_ int, d *fieldDecoder, _ *protocolHandler, _ *callContainer, _ *compressorCacher, _ NetworkInstrumenterStorage) error { if r.err = d.Decode(&r.seqno); r.err != nil { return r.err diff --git a/rpc/message_test.go b/rpc/message_test.go index a96e95f..8af8d8f 100644 --- a/rpc/message_test.go +++ b/rpc/message_test.go @@ -79,7 +79,7 @@ func TestMessageDecodeValidCompressed(t *testing.T) { } func TestMessageDecodeValidExtraParams(t *testing.T) { - tags := CtxRpcTags{"hello": "world"} + tags := CtxRPCTags{"hello": "world"} v := []interface{}{MethodCall, 999, "abc.hello", new(interface{}), tags, "foo"} rpc, err := runMessageTest(t, CompressionNone, v) @@ -91,7 +91,7 @@ func TestMessageDecodeValidExtraParams(t *testing.T) { require.Equal(t, CompressionNone, c.Compression()) require.Equal(t, "abc.hello", c.Name()) require.Equal(t, nil, c.Arg()) - resultTags, ok := RpcTagsFromContext(c.Context()) + resultTags, ok := TagsFromContext(c.Context()) require.True(t, ok) require.Equal(t, tags, resultTags) } diff --git a/rpc/packetizer_test.go b/rpc/packetizer_test.go index 89d2cb5..4f9b34c 100644 --- a/rpc/packetizer_test.go +++ b/rpc/packetizer_test.go @@ -241,7 +241,7 @@ func TestPacketizerDecodeInvalidFrames(t *testing.T) { name: "abc.hello", }, f1) require.EqualValues(t, sizes[0], record.Size) - require.Equal(t, RPCInstrumentTag(MethodCall, "abc.hello"), record.tag) + require.Equal(t, InstrumentTag(MethodCall, "abc.hello"), record.tag) f2, err := pkt.NextFrame() require.IsType(t, PacketizerError{}, err) @@ -259,7 +259,7 @@ func TestPacketizerDecodeInvalidFrames(t *testing.T) { name: "abc.hello", }, f4) require.EqualValues(t, sizes[3], record.Size) - require.Equal(t, RPCInstrumentTag(MethodNotify, "abc.hello"), record.tag) + require.Equal(t, InstrumentTag(MethodNotify, "abc.hello"), record.tag) f5, err := pkt.NextFrame() require.IsType(t, PacketizerError{}, err) @@ -275,10 +275,10 @@ func TestPacketizerDecodeInvalidFrames(t *testing.T) { responseErr: errors.New("response err"), }, f6) require.EqualValues(t, sizes[5], record.Size) - require.Equal(t, RPCInstrumentTag(MethodResponse, "foo.bar"), record.tag) + require.Equal(t, InstrumentTag(MethodResponse, "foo.bar"), record.tag) f7, err := pkt.NextFrame() - require.IsType(t, RPCDecodeError{}, err) + require.IsType(t, DecodeError{}, err) require.Nil(t, f7) f8, err := pkt.NextFrame() diff --git a/rpc/protocol_test.go b/rpc/protocol_test.go index 858787e..8ed019e 100644 --- a/rpc/protocol_test.go +++ b/rpc/protocol_test.go @@ -121,7 +121,7 @@ func TestLongCall(t *testing.T) { defer endTest(t, conn, listener) ctx := context.Background() - ctx = AddRpcTagsToContext(ctx, CtxRpcTags{"hello": []string{"world"}}) + ctx = AddRPCTagsToContext(ctx, CtxRPCTags{"hello": []string{"world"}}) longResult, err := cli.LongCall(ctx) require.NoError(t, err, "call should have succeeded") @@ -133,7 +133,7 @@ func TestCallCompressed(t *testing.T) { defer endTest(t, conn, listener) ctx := context.Background() - ctx = AddRpcTagsToContext(ctx, CtxRpcTags{"hello": []string{"world"}}) + ctx = AddRPCTagsToContext(ctx, CtxRPCTags{"hello": []string{"world"}}) nargs := NArgs{N: 50} verifyRes := func(res []*Constants, err error) { @@ -180,7 +180,7 @@ func TestLongCallCancel(t *testing.T) { defer endTest(t, conn, listener) ctx, cancel := context.WithCancel(context.Background()) - ctx = AddRpcTagsToContext(ctx, CtxRpcTags{"hello": []string{"world"}}) + ctx = AddRPCTagsToContext(ctx, CtxRPCTags{"hello": []string{"world"}}) resultCh := make(chan longCallResult) runInBg(func() error { @@ -207,7 +207,7 @@ func TestLongCallCancel(t *testing.T) { res = <-resultCh require.Nil(t, res.err, "call should have succeeded") - require.Equal(t, CtxRpcTags{"hello": []interface{}{"world"}}, res.res, "canceled call should have set the debug tags") + require.Equal(t, CtxRPCTags{"hello": []interface{}{"world"}}, res.res, "canceled call should have set the debug tags") } func TestLongCallTimeout(t *testing.T) { diff --git a/rpc/protocol_utils_test.go b/rpc/protocol_utils_test.go index 4a3b131..6193dfa 100644 --- a/rpc/protocol_utils_test.go +++ b/rpc/protocol_utils_test.go @@ -48,7 +48,7 @@ type testProtocol struct { c net.Conn constants Constants longCallResult int - debugTags CtxRpcTags + debugTags CtxRPCTags notifyCh chan struct{} } @@ -91,7 +91,7 @@ func (a *testProtocol) LongCall(ctx context.Context) (int, error) { defer func() { close(a.notifyCh) }() - tags, _ := RpcTagsFromContext(ctx) + tags, _ := TagsFromContext(ctx) a.debugTags = tags a.longCallResult = 0 for i := 0; i < 100; i++ { @@ -107,12 +107,12 @@ func (a *testProtocol) LongCall(ctx context.Context) (int, error) { return a.longCallResult, nil } -func (a *testProtocol) LongCallResult(ctx context.Context) (int, error) { +func (a *testProtocol) LongCallResult(_ context.Context) (int, error) { <-a.notifyCh return a.longCallResult, nil } -func (a *testProtocol) LongCallDebugTags(ctx context.Context) (CtxRpcTags, error) { +func (a *testProtocol) LongCallDebugTags(_ context.Context) (CtxRPCTags, error) { return a.debugTags, nil } @@ -140,7 +140,7 @@ type TestInterface interface { GetNConstants(*NArgs) ([]*Constants, error) LongCall(context.Context) (int, error) LongCallResult(context.Context) (int, error) - LongCallDebugTags(context.Context) (CtxRpcTags, error) + LongCallDebugTags(context.Context) (CtxRPCTags, error) } func createTestProtocol(i TestInterface) Protocol { @@ -266,7 +266,7 @@ func (a TestClient) LongCallResult(ctx context.Context) (ret int, err error) { return ret, err } -func (a TestClient) LongCallDebugTags(ctx context.Context) (ret CtxRpcTags, err error) { +func (a TestClient) LongCallDebugTags(ctx context.Context) (ret CtxRPCTags, err error) { err = a.Call(ctx, "test.1.testp.LongCallDebugTags", nil, &ret, 0) return ret, err } diff --git a/rpc/receiver_test.go b/rpc/receiver_test.go index 9de0354..f636b6d 100644 --- a/rpc/receiver_test.go +++ b/rpc/receiver_test.go @@ -98,7 +98,7 @@ func TestCloseReceiver(t *testing.T) { MakeArg: func() interface{} { return nil }, - Handler: func(c context.Context, i interface{}) (interface{}, error) { + Handler: func(c context.Context, _ interface{}) (interface{}, error) { <-c.Done() waitCh <- c.Err() return nil, c.Err() diff --git a/rpc/request.go b/rpc/request.go index 7040c58..c80e544 100644 --- a/rpc/request.go +++ b/rpc/request.go @@ -176,7 +176,7 @@ func (r *notifyRequest) LogCompletion(_ interface{}, err error) { r.log.ServerNotifyComplete(r.Name(), err) } -func (r *notifyRequest) Serve(transmitter *framedMsgpackEncoder, handler *ServeHandlerDescription, wrapErrorFunc WrapErrorFunc) { +func (r *notifyRequest) Serve(_ *framedMsgpackEncoder, handler *ServeHandlerDescription, _ WrapErrorFunc) { prof := r.log.StartProfiler("serve-notify %s", r.Name()) arg := r.Arg() @@ -187,6 +187,6 @@ func (r *notifyRequest) Serve(transmitter *framedMsgpackEncoder, handler *ServeH r.LogCompletion(nil, err) } -func (r *notifyRequest) Reply(enc *framedMsgpackEncoder, res interface{}, errArg interface{}) (err error) { +func (r *notifyRequest) Reply(_ *framedMsgpackEncoder, _ interface{}, _ interface{}) (err error) { return nil } diff --git a/rpc/resinit/resinit.go b/rpc/resinit/resinit.go index 4c3383e..90ce127 100644 --- a/rpc/resinit/resinit.go +++ b/rpc/resinit/resinit.go @@ -7,7 +7,7 @@ import "net" // platforms. See implementation details in resinit_linux.go. The Rust standard // library contains a similar workaround: // https://github.com/rust-lang/rust/blob/028569ab1b/src/libstd/sys_common/net.rs#L186-L190 -func ResInitIfDNSError(err error) { +func IfDNSError(err error) { // There are two error cases we need to handle, a raw *net.DNSError, and // one wrapped in a *net.OpError. Detect that second case, and unwrap it. if opErr, isOpErr := err.(*net.OpError); isOpErr { From 04d3375fe8f7f14db464a027575c0de889d7ed8c Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Mon, 6 Jan 2025 15:09:31 -0500 Subject: [PATCH 2/5] upgrade msgpackzip --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1b1f79e..18a8173 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/keybase/backoff v1.0.1-0.20160517061000-726b63b835ec github.com/keybase/go-codec v0.0.0-20180928230036-164397562123 - github.com/keybase/msgpackzip v0.0.0-20250106182721-6f0080476008 + github.com/keybase/msgpackzip v0.0.0-20250106200500-93bf3a4c34cf github.com/reiver/go-telnet v0.0.0-20180421082511-9ff0b2ab096e github.com/stretchr/testify v1.10.0 golang.org/x/net v0.19.0 diff --git a/go.sum b/go.sum index 7d132d7..470e2b0 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/keybase/backoff v1.0.1-0.20160517061000-726b63b835ec h1:D6qL2WCnAuxuc github.com/keybase/backoff v1.0.1-0.20160517061000-726b63b835ec/go.mod h1:jeBKj+20GIDry3doFsAMYH9n7Y3l7ajE3xJrKvVB23s= github.com/keybase/go-codec v0.0.0-20180928230036-164397562123 h1:yg56lYPqh9suJepqxOMd/liFgU/x+maRPiB30JNYykM= github.com/keybase/go-codec v0.0.0-20180928230036-164397562123/go.mod h1:r/eVVWCngg6TsFV/3HuS9sWhDkAzGG8mXhiuYA+Z/20= -github.com/keybase/msgpackzip v0.0.0-20250106182721-6f0080476008 h1:eGLsSh7V10/j3WBZAW7k2kUzvz88M2qdmpMY4L7wyXk= -github.com/keybase/msgpackzip v0.0.0-20250106182721-6f0080476008/go.mod h1:XGERKRnPD1bFQJrhQp5XHw4JtZ+u3nlgdx/xrwF13ow= +github.com/keybase/msgpackzip v0.0.0-20250106200500-93bf3a4c34cf h1:wG5lhAbfl5Gir35gAdJywwf7tEjPW9oI0jBjzQZysxQ= +github.com/keybase/msgpackzip v0.0.0-20250106200500-93bf3a4c34cf/go.mod h1:XGERKRnPD1bFQJrhQp5XHw4JtZ+u3nlgdx/xrwF13ow= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/reiver/go-oi v1.0.0 h1:nvECWD7LF+vOs8leNGV/ww+F2iZKf3EYjYZ527turzM= From 59d141715712193925ba866de9e570829d52ad75 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Mon, 6 Jan 2025 15:27:26 -0500 Subject: [PATCH 3/5] Update minor libs --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 18a8173..309c868 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,8 @@ require ( github.com/keybase/msgpackzip v0.0.0-20250106200500-93bf3a4c34cf github.com/reiver/go-telnet v0.0.0-20180421082511-9ff0b2ab096e github.com/stretchr/testify v1.10.0 - golang.org/x/net v0.19.0 - golang.org/x/sync v0.5.0 + golang.org/x/net v0.34.0 + golang.org/x/sync v0.10.0 ) require ( diff --git a/go.sum b/go.sum index 470e2b0..ebc823a 100644 --- a/go.sum +++ b/go.sum @@ -14,10 +14,10 @@ github.com/reiver/go-telnet v0.0.0-20180421082511-9ff0b2ab096e h1:quuzZLi72kkJjl github.com/reiver/go-telnet v0.0.0-20180421082511-9ff0b2ab096e/go.mod h1:+5vNVvEWwEIx86DB9Ke/+a5wBI464eDRo3eF0LcfpWg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From c594d07371430bb980bb015e43eec056aa08045d Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Mon, 6 Jan 2025 15:32:45 -0500 Subject: [PATCH 4/5] revive non darwin --- rpc/sigpipe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/sigpipe.go b/rpc/sigpipe.go index 26f2d16..826fa71 100644 --- a/rpc/sigpipe.go +++ b/rpc/sigpipe.go @@ -5,6 +5,6 @@ package rpc import "net" -func DisableSigPipe(c net.Conn) error { +func DisableSigPipe(_ net.Conn) error { return nil } From d8fff7e998647f16018720011c077189e73be0b5 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Mon, 6 Jan 2025 15:41:38 -0500 Subject: [PATCH 5/5] test race --- rpc/connection_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rpc/connection_test.go b/rpc/connection_test.go index f6e9b2d..cb57574 100644 --- a/rpc/connection_test.go +++ b/rpc/connection_test.go @@ -357,8 +357,9 @@ func TestDialableTransport(t *testing.T) { } output := testLogOutput{t: t} opts := ConnectionOpts{ - WrapErrorFunc: testWrapError, - TagsFunc: testLogTags, + WrapErrorFunc: testWrapError, + TagsFunc: testLogTags, + DontConnectNow: true, } uriStr := "fmprpc://localhost:8080" @@ -400,8 +401,9 @@ func TestDialableTLSConn(t *testing.T) { } output := testLogOutput{t: t} opts := ConnectionOpts{ - WrapErrorFunc: testWrapError, - TagsFunc: testLogTags, + WrapErrorFunc: testWrapError, + TagsFunc: testLogTags, + DontConnectNow: true, } uriStr := "fmprpc+tls://localhost:8080"