Skip to content

Commit

Permalink
fix duplicate error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Jan 4, 2021
1 parent 9e40791 commit 9ef971c
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 71 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ jobs:
else
go get -v -t -d ./...
fi
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0

- name: Run Linter
run: golangci-lint run --timeout=10m -v

- name: Verify
run: |
make verify
- name: Integrate Test
run: |
chmod +x integrate_test.sh && ./integrate_test.sh
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0

- name: Run Linter
run: golangci-lint run --timeout=10m -v
- name: Post Coverage
run: bash <(curl -s https://codecov.io/bash)
Expand Down
6 changes: 3 additions & 3 deletions cluster/router/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ conditions:
_, err = z.Conn.Set(path, []byte(testyml), 0)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()
Expand Down Expand Up @@ -209,7 +209,7 @@ conditions:
_, err = z.Conn.Set(path, []byte(testyml), 0)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestRouterChainRouteNoRoute(t *testing.T) {
ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second)
assert.Nil(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()
Expand Down
4 changes: 2 additions & 2 deletions config_center/apollo/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func (c *apolloConfiguration) getAddressWithProtocolPrefix(url *common.URL) stri
address := url.Location
converted := address
if len(address) != 0 {
address := regexp.MustCompile(`\s+`).ReplaceAllString(address, "")
parts := strings.Split(address, ",")
addr := regexp.MustCompile(`\s+`).ReplaceAllString(address, "")
parts := strings.Split(addr, ",")
addrs := make([]string, 0)
for _, part := range parts {
addr := part
Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/dubbo_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *DubboCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer, er
return pkg.Marshal()
}

// encode heartbeart request
// encode heartbeat request
func (c *DubboCodec) encodeHeartbeartReqeust(request *remoting.Request) (*bytes.Buffer, error) {
header := impl.DubboHeader{
Type: impl.PackageHeartbeat,
Expand Down
6 changes: 3 additions & 3 deletions protocol/dubbo/hessian2/hessian_dubbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ func (h *HessianCodec) ReadBody(rspObj interface{}) error {
switch h.pkgType & PackageType_BitSize {
case PackageResponse | PackageHeartbeat | PackageResponse_Exception, PackageResponse | PackageResponse_Exception:
decoder := hessian.NewDecoder(buf[:])
exception, err := decoder.Decode()
if err != nil {
return perrors.WithStack(err)
exception, exceptionErr := decoder.Decode()
if exceptionErr != nil {
return perrors.WithStack(exceptionErr)
}
rsp, ok := rspObj.(*DubboResponse)
if !ok {
Expand Down
12 changes: 5 additions & 7 deletions protocol/dubbo/hessian2/hessian_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,21 @@ func packRequest(service Service, header DubboHeader, req interface{}) ([]byte,
// body
//////////////////////////////////////////
if hb {
if err := encoder.Encode(nil); err != nil {
logger.Warnf("Encode(nil) = error: %v", err)
}
_ = encoder.Encode(nil)
goto END
}

// dubbo version + path + version + method
if err := encoder.Encode(DEFAULT_DUBBO_PROTOCOL_VERSION); err != nil {
if err = encoder.Encode(DEFAULT_DUBBO_PROTOCOL_VERSION); err != nil {
logger.Warnf("Encode(DEFAULT_DUBBO_PROTOCOL_VERSION) = error: %v", err)
}
if err := encoder.Encode(service.Path); err != nil {
if err = encoder.Encode(service.Path); err != nil {
logger.Warnf("Encode(service.Path) = error: %v", err)
}
if err := encoder.Encode(service.Version); err != nil {
if err = encoder.Encode(service.Version); err != nil {
logger.Warnf("Encode(service.Version) = error: %v", err)
}
if err := encoder.Encode(service.Method); err != nil {
if err = encoder.Encode(service.Method); err != nil {
logger.Warnf("Encode(service.Method) = error: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/grpc/protoc-gen-dubbo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
g.Error(err, "reading input")
}

if err := proto.Unmarshal(data, g.Request); err != nil {
if err = proto.Unmarshal(data, g.Request); err != nil {
g.Error(err, "parsing input proto")
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/jsonrpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte)

return conn.SetDeadline(t)
}
if err := setNetConnTimeout(tcpConn, c.options.HTTPTimeout); err != nil {
if err = setNetConnTimeout(tcpConn, c.options.HTTPTimeout); err != nil {
return nil, err
}

Expand Down
15 changes: 9 additions & 6 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
dataListener.mutex.Lock()
defer dataListener.mutex.Unlock()
if r.dataListener.subscribed[conf.ServiceKey()] != nil {

zkListener, _ := r.dataListener.subscribed[conf.ServiceKey()].(*RegistryConfigurationListener)
zkListener, _ = r.dataListener.subscribed[conf.ServiceKey()].(*RegistryConfigurationListener)
if zkListener != nil {
r.listenerLock.Lock()
defer r.listenerLock.Unlock()
Expand Down Expand Up @@ -284,7 +283,11 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
//Interested register to dataconfig.
r.dataListener.SubscribeURL(conf, zkListener)

go r.listener.ListenServiceEvent(conf, fmt.Sprintf("/dubbo/%s/"+constant.DEFAULT_CATEGORY, url.QueryEscape(conf.Service())), r.dataListener)
go r.listener.ListenServiceEvent(
conf,
fmt.Sprintf("/dubbo/%s/"+constant.DEFAULT_CATEGORY, url.QueryEscape(conf.Service())),
r.dataListener,
)

return zkListener, nil
}
Expand All @@ -295,9 +298,9 @@ func (r *zkRegistry) getCloseListener(conf *common.URL) (*RegistryConfigurationL
r.dataListener.mutex.Lock()
configurationListener := r.dataListener.subscribed[conf.ServiceKey()]
if configurationListener != nil {
zkListener, _ := configurationListener.(*RegistryConfigurationListener)
if zkListener != nil {
if zkListener.isClosed {
rcListener, _ := configurationListener.(*RegistryConfigurationListener)
if rcListener != nil {
if rcListener.isClosed {
r.dataListener.mutex.Unlock()
return nil, perrors.New("configListener already been closed")
}
Expand Down
8 changes: 2 additions & 6 deletions registry/zookeeper/service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func TestCURDZookeeperServiceDiscovery(t *testing.T) {
sd, err := newZookeeperServiceDiscovery(testName)
assert.Nil(t, err)
defer func() {
err := sd.Destroy()
assert.Nil(t, err)
_ = sd.Destroy()
}()
md := make(map[string]string)
md["t1"] = "test1"
Expand Down Expand Up @@ -151,8 +150,7 @@ func TestAddListenerZookeeperServiceDiscovery(t *testing.T) {
sd, err := newZookeeperServiceDiscovery(testName)
assert.Nil(t, err)
defer func() {
err := sd.Destroy()
assert.Nil(t, err)
_ = sd.Destroy()
}()

err = sd.Register(&registry.DefaultServiceInstance{
Expand All @@ -164,8 +162,6 @@ func TestAddListenerZookeeperServiceDiscovery(t *testing.T) {
Healthy: true,
Metadata: nil,
})
assert.Nil(t, err)

assert.Nil(t, err)
wg := &sync.WaitGroup{}
wg.Add(1)
Expand Down
2 changes: 1 addition & 1 deletion remoting/getty/dubbo_codec_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *DubboTestCodec) EncodeRequest(request *remoting.Request) (*bytes.Buffer
return pkg.Marshal()
}

// encode heartbeart request
// encode heartbeat request
func (c *DubboTestCodec) encodeHeartbeartReqeust(request *remoting.Request) (*bytes.Buffer, error) {
header := impl.DubboHeader{
Type: impl.PackageHeartbeat,
Expand Down
6 changes: 3 additions & 3 deletions remoting/getty/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
}
h.rwlock.Unlock()

decodeResult, ok := pkg.(remoting.DecodeResult)
if !ok {
decodeResult, drOK := pkg.(remoting.DecodeResult)
if !drOK {
logger.Errorf("illegal package{%#v}", pkg)
return
}
Expand All @@ -252,7 +252,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
res.Handle()
return
}
logger.Errorf("illegal package but not heartbeart. {%#v}", pkg)
logger.Errorf("illegal package but not heartbeat. {%#v}", pkg)
return
}
req := decodeResult.Result.(*remoting.Request)
Expand Down
22 changes: 11 additions & 11 deletions remoting/getty/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,25 @@ func (c *gettyRPCClient) updateSession(session getty.Session) {

func (c *gettyRPCClient) getClientRpcSession(session getty.Session) (rpcSession, error) {
var (
err error
rpcSession rpcSession
err error
rs rpcSession
)
c.lock.RLock()
defer c.lock.RUnlock()
if c.sessions == nil {
return rpcSession, errClientClosed
return rs, errClientClosed
}

err = errSessionNotExist
for _, s := range c.sessions {
if s.session == session {
rpcSession = *s
rs = *s
err = nil
break
}
}

return rpcSession, perrors.WithStack(err)
return rs, perrors.WithStack(err)
}

func (c *gettyRPCClient) isAvailable() bool {
Expand Down Expand Up @@ -363,16 +363,16 @@ func (p *gettyRPCClientPool) close() {
}

func (p *gettyRPCClientPool) getGettyRpcClient(addr string) (*gettyRPCClient, error) {
conn, err := p.get()
if err == nil && conn == nil {
conn, connErr := p.get()
if connErr == nil && conn == nil {
// create new conn
rpcClientConn, err := newGettyRPCClientConn(p, addr)
if err == nil {
rpcClientConn, rpcErr := newGettyRPCClientConn(p, addr)
if rpcErr == nil {
p.put(rpcClientConn)
}
return rpcClientConn, perrors.WithStack(err)
return rpcClientConn, perrors.WithStack(rpcErr)
}
return conn, perrors.WithStack(err)
return conn, perrors.WithStack(connErr)
}

func (p *gettyRPCClientPool) get() (*gettyRPCClient, error) {
Expand Down
18 changes: 9 additions & 9 deletions remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ func ValidateZookeeperClient(container ZkClientFacade, opts ...Option) error {

if container.ZkClient() == nil {
// in dubbo, every registry only connect one node, so this is []string{r.Address}
timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if err != nil {
logger.Errorf("timeout config %v is invalid ,err is %v",
url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err.Error())
return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", url.Location)
timeout, paramErr := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if paramErr != nil {
logger.Errorf("timeout config %v is invalid, err is %v",
url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), paramErr.Error())
return perrors.WithMessagef(paramErr, "newZookeeperClient(address:%+v)", url.Location)
}
zkAddresses := strings.Split(url.Location, ",")
newClient, err := NewZookeeperClient(options.zkName, zkAddresses, timeout)
if err != nil {
newClient, cltErr := NewZookeeperClient(options.zkName, zkAddresses, timeout)
if cltErr != nil {
logger.Warnf("newZookeeperClient(name{%s}, zk address{%v}, timeout{%d}) = error{%v}",
options.zkName, url.Location, timeout.String(), err)
return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", url.Location)
options.zkName, url.Location, timeout.String(), cltErr)
return perrors.WithMessagef(cltErr, "newZookeeperClient(address:%+v)", url.Location)
}
container.SetZkClient(newClient)
connected = true
Expand Down
8 changes: 4 additions & 4 deletions remoting/zookeeper/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestCreate(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("test1/test2/test3/test4")
Expand All @@ -110,7 +110,7 @@ func TestCreateDelete(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.Nil(t, err)
}()

Expand All @@ -127,7 +127,7 @@ func TestRegisterTemp(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("/test1/test2/test3")
Expand All @@ -144,7 +144,7 @@ func TestRegisterTempSeq(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("/test1/test2/test3")
Expand Down
14 changes: 8 additions & 6 deletions remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li
newChildren, err := l.client.GetChildren(zkPath)
if err != nil {
if err == errNilChildren {
content, _, err := l.client.Conn.Get(zkPath)
if err != nil {
logger.Errorf("Get new node path {%v} 's content error,message is {%v}", zkPath, perrors.WithStack(err))
content, _, connErr := l.client.Conn.Get(zkPath)
if connErr != nil {
logger.Errorf("Get new node path {%v} 's content error,message is {%v}",
zkPath, perrors.WithStack(connErr))
} else {
listener.DataChange(remoting.Event{Path: zkPath, Action: remoting.EventTypeUpdate, Content: string(content)})
}
Expand All @@ -158,9 +159,10 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li

newNode = path.Join(zkPath, n)
logger.Infof("add zkNode{%s}", newNode)
content, _, err := l.client.Conn.Get(newNode)
if err != nil {
logger.Errorf("Get new node path {%v} 's content error,message is {%v}", newNode, perrors.WithStack(err))
content, _, connErr := l.client.Conn.Get(newNode)
if connErr != nil {
logger.Errorf("Get new node path {%v} 's content error,message is {%v}",
newNode, perrors.WithStack(connErr))
}

if !listener.DataChange(remoting.Event{Path: zkPath, Action: remoting.EventTypeAdd, Content: string(content)}) {
Expand Down

0 comments on commit 9ef971c

Please sign in to comment.