Skip to content

Commit 36d8456

Browse files
committed
Merge upstream 'v1.8.31'
2 parents 154ac5d + b4444e9 commit 36d8456

File tree

12 files changed

+189
-178
lines changed

12 files changed

+189
-178
lines changed

โ€ŽREADME.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ you can use other programming languages besides Go to access rpcx services.
3030

3131
- **rpcx-gateway**: You can write clients in any programming languages to call rpcx services via [rpcx-gateway](https://github.com/rpcxio/rpcx-gateway)
3232
- **http invoke**: you can use the same http requests to access rpcx gateway
33-
- **Java Services/Clients**: You can use [rpcx-java](https://github.com/smallnest/rpcx-java) to implement/access rpcx servies via raw protocol.
33+
- **Java Services/Clients**: You can use [rpcx-java](https://github.com/smallnest/rpcx-java) to implement/access rpcx services via raw protocol.
3434
- **rust rpcx**: You can write rpcx services in rust by [rpcx-rs](https://github.com/smallnest/rpcx-rs)
3535

3636
> If you can write Go methods, you can also write rpc services. It is so easy to write rpc applications with rpcx.
@@ -67,8 +67,8 @@ go get -v -tags "quic kcp" github.com/smallnest/rpcx/...
6767
rpcx is a RPC framework like [Alibaba Dubbo](http://dubbo.io/) and [Weibo Motan](https://github.com/weibocom/motan).
6868

6969
**rpcx** is created for targets:
70-
1. **Simple**: easy to learn, easy to develop, easy to intergate and easy to deploy
71-
2. **Performance**: high perforamnce (>= grpc-go)
70+
1. **Simple**: easy to learn, easy to develop, easy to integrate and easy to deploy
71+
2. **Performance**: high performance (>= grpc-go)
7272
3. **Cross-platform**: support _raw slice of bytes_, _JSON_, _Protobuf_ and _MessagePack_. Theoretically it can be used with java, php, python, c/c++, node.js, c# and other platforms
7373
4. **Service discovery and service governance**: support zookeeper, etcd and consul.
7474

โ€Žclient/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ type Call struct {
213213
}
214214

215215
func (call *Call) done() {
216+
if call.Done == nil { // Oneshot
217+
return
218+
}
219+
216220
select {
217221
case call.Done <- call:
218222
// ok

โ€Žclient/xclient.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,18 @@ func filterByStateAndGroup(group string, servers map[string]string) {
235235
if state := values.Get("state"); state == "inactive" {
236236
delete(servers, k)
237237
}
238-
if group != "" && group != values.Get("group") {
239-
delete(servers, k)
238+
groups := values["group"] // Directly access the map to get all values associated with "group" as a slice
239+
if group != "" {
240+
found := false
241+
for _, g := range groups {
242+
if group == g {
243+
found = true
244+
break // A matching group is found, stop the search
245+
}
246+
}
247+
if !found {
248+
delete(servers, k) // If no matching group is found, delete the corresponding server from the map
249+
}
240250
}
241251
}
242252
}
@@ -245,6 +255,13 @@ func filterByStateAndGroup(group string, servers map[string]string) {
245255
// selects a client from candidates base on c.selectMode
246256
func (c *xClient) selectClient(ctx context.Context, servicePath, serviceMethod string, args interface{}) (string, RPCClient, error) {
247257
c.mu.Lock()
258+
259+
if c.option.Sticky && c.stickyRPCClient != nil {
260+
if c.stickyRPCClient.IsClosing() || c.stickyRPCClient.IsShutdown() {
261+
c.stickyRPCClient = nil
262+
}
263+
}
264+
248265
if c.option.Sticky && c.stickyRPCClient != nil {
249266
c.mu.Unlock()
250267
return c.stickyK, c.stickyRPCClient, nil
@@ -264,13 +281,29 @@ func (c *xClient) selectClient(ctx context.Context, servicePath, serviceMethod s
264281
client, err := c.getCachedClient(k, servicePath, serviceMethod, args)
265282

266283
if c.option.Sticky && client != nil {
284+
c.mu.Lock()
285+
safeCloseClient(c.stickyRPCClient)
286+
267287
c.stickyK = k
268288
c.stickyRPCClient = client
289+
c.mu.Unlock()
269290
}
270291

271292
return k, client, err
272293
}
273294

295+
func safeCloseClient(client RPCClient) {
296+
if client == nil {
297+
return
298+
}
299+
300+
defer func() {
301+
_ = recover()
302+
}()
303+
304+
client.Close()
305+
}
306+
274307
func (c *xClient) getCachedClient(k string, servicePath, serviceMethod string, args interface{}) (RPCClient, error) {
275308
// TODO: improve the lock
276309
var client RPCClient

โ€Žclient/xclient_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestXClient_IT(t *testing.T) {
9393
}
9494

9595
func TestXClient_filterByStateAndGroup(t *testing.T) {
96-
servers := map[string]string{"a": "", "b": "state=inactive&ops=10", "c": "ops=20", "d": "group=test&ops=20"}
96+
servers := map[string]string{"a": "", "b": "state=inactive&ops=10", "c": "ops=20", "d": "group=test1&group=test&ops=20"}
9797
filterByStateAndGroup("test", servers)
9898
if _, ok := servers["b"]; ok {
9999
t.Error("has not remove inactive node")
@@ -107,6 +107,12 @@ func TestXClient_filterByStateAndGroup(t *testing.T) {
107107
if _, ok := servers["d"]; !ok {
108108
t.Error("node must be removed")
109109
}
110+
111+
filterByStateAndGroup("test1", servers)
112+
113+
if _, ok := servers["d"]; !ok {
114+
t.Error("node must be removed")
115+
}
110116
}
111117

112118
func TestUncoverError(t *testing.T) {

โ€Žcodec/codec.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
pb "google.golang.org/protobuf/proto"
109
"reflect"
1110

11+
pb "google.golang.org/protobuf/proto"
12+
1213
"github.com/apache/thrift/lib/go/thrift"
1314
"github.com/gogo/protobuf/proto"
14-
jsoniter "github.com/json-iterator/go"
1515
"github.com/tinylib/msgp/msgp"
1616
"github.com/vmihailenco/msgpack/v5"
1717
)
@@ -142,20 +142,3 @@ func (c ThriftCodec) Decode(data []byte, i interface{}) error {
142142
d.Transport.Close()
143143
return d.Read(context.Background(), i.(thrift.TStruct), data)
144144
}
145-
146-
type JSONIterCodec struct{}
147-
148-
func (c JSONIterCodec) Encode(i interface{}) ([]byte, error) {
149-
var buf bytes.Buffer
150-
enc := jsoniter.NewEncoder(&buf)
151-
enc.SetEscapeHTML(false)
152-
err := enc.Encode(i)
153-
return buf.Bytes(), err
154-
}
155-
156-
// Decode decodes an object from slice of bytes.
157-
func (c JSONIterCodec) Decode(data []byte, i interface{}) error {
158-
d := jsoniter.NewDecoder(bytes.NewBuffer(data))
159-
d.UseNumber()
160-
return d.Decode(i)
161-
}

โ€Žgo.mod

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
module github.com/smallnest/rpcx
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.22.1
46

57
require (
68
github.com/ChimeraCoder/gojson v1.1.0
79
github.com/akutz/memconn v0.1.0
810
github.com/alitto/pond v1.8.3
9-
github.com/apache/thrift v0.18.1
11+
github.com/apache/thrift v0.20.0
1012
github.com/edwingeng/doublejump v1.0.1
11-
github.com/fatih/color v1.14.1
12-
github.com/go-echarts/go-echarts/v2 v2.3.2
13+
github.com/fatih/color v1.16.0
14+
github.com/go-echarts/go-echarts/v2 v2.3.3
1315
github.com/go-ping/ping v1.1.0
1416
github.com/go-redis/redis/v8 v8.11.5
1517
github.com/go-redis/redis_rate/v9 v9.1.2
@@ -19,71 +21,70 @@ require (
1921
github.com/golang/snappy v0.0.4
2022
github.com/grandcat/zeroconf v1.0.0
2123
github.com/hashicorp/go-multierror v1.1.1
22-
github.com/hashicorp/golang-lru v0.5.4
24+
github.com/hashicorp/golang-lru v1.0.2
2325
github.com/jamiealquiza/tachymeter v2.0.0+incompatible
24-
github.com/json-iterator/go v1.1.12
2526
github.com/juju/ratelimit v1.0.2
2627
github.com/julienschmidt/httprouter v1.3.0
2728
github.com/kavu/go_reuseport v1.5.0
2829
github.com/kr/pretty v0.2.0
29-
github.com/quic-go/quic-go v0.37.7
30+
github.com/quic-go/quic-go v0.43.1
3031
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
3132
github.com/rpcxio/libkv v0.5.1
32-
github.com/rs/cors v1.8.3
33+
github.com/rs/cors v1.11.0
3334
github.com/rubyist/circuitbreaker v2.2.1+incompatible
34-
github.com/smallnest/quick v0.1.0
35-
github.com/smallnest/statsview v0.0.0-20231119085602-10700f9abec4
35+
github.com/smallnest/quick v0.2.0
36+
github.com/smallnest/statsview v1.0.1
3637
github.com/soheilhy/cmux v0.1.5
37-
github.com/stretchr/testify v1.7.2
38-
github.com/tinylib/msgp v1.1.8
38+
github.com/stretchr/testify v1.8.4
39+
github.com/tinylib/msgp v1.1.9
3940
github.com/valyala/fastrand v1.1.0
4041
github.com/vmihailenco/msgpack/v5 v5.3.5
4142
github.com/xtaci/kcp-go v5.4.20+incompatible
42-
golang.org/x/net v0.17.0
43-
golang.org/x/sync v0.2.0
44-
google.golang.org/protobuf v1.33.0
43+
golang.org/x/net v0.25.0
44+
golang.org/x/sync v0.7.0
45+
google.golang.org/protobuf v1.34.1
4546
)
4647

4748
require (
49+
github.com/StackExchange/wmi v1.2.1 // indirect
4850
github.com/cenk/backoff v2.2.1+incompatible // indirect
4951
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
50-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
52+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5153
github.com/davecgh/go-spew v1.1.1 // indirect
5254
github.com/dgryski/go-jump v0.0.0-20211018200510-ba001c3ffce0 // indirect
5355
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
5456
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
5557
github.com/fsnotify/fsnotify v1.6.0 // indirect
56-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
57-
github.com/golang/mock v1.6.0 // indirect
58-
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect
59-
github.com/google/uuid v1.3.0 // indirect
58+
github.com/go-ole/go-ole v1.3.0 // indirect
59+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
60+
github.com/google/pprof v0.0.0-20240430035430-e4905b036c4e // indirect
61+
github.com/google/uuid v1.6.0 // indirect
6062
github.com/hashicorp/errwrap v1.1.0 // indirect
61-
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
62-
github.com/klauspost/reedsolomon v1.11.7 // indirect
63+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
64+
github.com/klauspost/reedsolomon v1.12.1 // indirect
6365
github.com/kr/text v0.1.0 // indirect
64-
github.com/libp2p/go-sockaddr v0.1.1 // indirect
66+
github.com/libp2p/go-sockaddr v0.2.0 // indirect
6567
github.com/mattn/go-colorable v0.1.13 // indirect
66-
github.com/mattn/go-isatty v0.0.17 // indirect
67-
github.com/miekg/dns v1.1.51 // indirect
68-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
69-
github.com/modern-go/reflect2 v1.0.2 // indirect
70-
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
68+
github.com/mattn/go-isatty v0.0.20 // indirect
69+
github.com/miekg/dns v1.1.59 // indirect
70+
github.com/onsi/ginkgo/v2 v2.17.2 // indirect
7171
github.com/peterbourgon/g2s v0.0.0-20140925154142-ec76db4c1ac1 // indirect
7272
github.com/philhofer/fwd v1.1.2 // indirect
7373
github.com/pkg/errors v0.9.1 // indirect
7474
github.com/pmezard/go-difflib v1.0.0 // indirect
75-
github.com/quic-go/qtls-go1-20 v0.3.1 // indirect
75+
github.com/shirou/gopsutil/v3 v3.20.10 // indirect
7676
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
7777
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
7878
github.com/tjfoc/gmsm v1.4.1 // indirect
7979
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
8080
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect
81-
golang.org/x/crypto v0.17.0 // indirect
82-
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
83-
golang.org/x/mod v0.10.0 // indirect
84-
golang.org/x/sys v0.15.0 // indirect
85-
golang.org/x/text v0.14.0 // indirect
86-
golang.org/x/tools v0.9.1 // indirect
81+
go.uber.org/mock v0.4.0 // indirect
82+
golang.org/x/crypto v0.23.0 // indirect
83+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
84+
golang.org/x/mod v0.17.0 // indirect
85+
golang.org/x/sys v0.20.0 // indirect
86+
golang.org/x/text v0.15.0 // indirect
87+
golang.org/x/tools v0.21.0 // indirect
8788
gopkg.in/yaml.v2 v2.4.0 // indirect
8889
gopkg.in/yaml.v3 v3.0.1 // indirect
8990
)

0 commit comments

Comments
ย (0)