Skip to content

Commit dd39b82

Browse files
authored
Merge pull request #748 from cloudwego/release/v0.4.4
chore: release v0.4.4
2 parents 0f18091 + 9f50f5e commit dd39b82

55 files changed

Lines changed: 3597 additions & 617 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yml

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,49 @@ name: Tests
33
on: [ push, pull_request ]
44

55
jobs:
6-
unit-benchmark-test:
6+
unit-scenario-test:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
1010
- name: Set up Go
1111
uses: actions/setup-go@v3
1212
with:
13-
go-version: '1.16'
13+
go-version: '1.17'
1414
- name: Unit Test
15-
run: go test -gcflags all=-N -l -race -covermode=atomic -coverprofile=coverage.txt ./...
15+
run: go test -gcflags=-l -race -covermode=atomic -coverprofile=coverage.txt ./...
16+
- name: Scenario Tests
17+
run: |
18+
cd ..
19+
rm -rf kitex-tests
20+
git clone https://github.com/cloudwego/kitex-tests.git
21+
cd kitex-tests
22+
./run.sh ${{github.workspace}}
23+
cd ${{github.workspace}}
1624
- name: Codecov
1725
run: bash <(curl -s https://codecov.io/bash)
18-
- name: Benchmark
19-
run: go test -gcflags all=-N -l -bench=. -benchmem -run=none ./...
2026

21-
compatibility-test:
22-
strategy:
23-
matrix:
24-
go: [ 1.15, 1.17, 1.18, 1.19 ]
25-
os: [ X64, ARM64 ]
26-
runs-on: ${{ matrix.os }}
27+
benchmark-test:
28+
runs-on: ubuntu-latest
2729
steps:
2830
- uses: actions/checkout@v3
2931
- name: Set up Go
3032
uses: actions/setup-go@v3
3133
with:
32-
go-version: ${{ matrix.go }}
33-
- name: Unit Test
34-
run: go test -gcflags all=-N -l -race -covermode=atomic -coverprofile=coverage.txt ./...
34+
go-version: '1.17'
35+
- name: Benchmark
36+
run: go test -gcflags='all=-N -l' -bench=. -benchmem -run=none ./...
3537

36-
scenario-test:
38+
compatibility-test:
3739
strategy:
3840
matrix:
39-
go: [ 1.16, 1.18 ]
40-
runs-on: [ self-hosted, X64 ]
41+
go: [ 1.15, 1.16, 1.18, 1.19 ]
42+
os: [ X64, ARM64 ]
43+
runs-on: ${{ matrix.os }}
4144
steps:
4245
- uses: actions/checkout@v3
43-
- uses: actions/setup-python@v4
44-
with:
45-
python-version: '3.x'
46-
architecture: x64
4746
- name: Set up Go
4847
uses: actions/setup-go@v3
4948
with:
5049
go-version: ${{ matrix.go }}
51-
- name: Scenario Tests
52-
run: |
53-
cd ..
54-
rm -rf kitex-tests
55-
git clone https://github.com/cloudwego/kitex-tests.git
56-
cd kitex-tests
57-
./run.sh ${{github.workspace}}
50+
- name: Unit Test
51+
run: go test -gcflags=-l -race -covermode=atomic -coverprofile=coverage.txt ./...

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ English | [中文](README_cn.md)
1010
[![ClosedIssue](https://img.shields.io/github/issues-closed/cloudwego/kitex)](https://github.com/cloudwego/kitex/issues?q=is%3Aissue+is%3Aclosed)
1111
![Stars](https://img.shields.io/github/stars/cloudwego/kitex)
1212
![Forks](https://img.shields.io/github/forks/cloudwego/kitex)
13+
[![Slack](https://img.shields.io/badge/slack-join_chat-success.svg?logo=slack)](https://cloudwego.slack.com/join/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA)
1314

1415
Kitex [kaɪt'eks] is a **high-performance** and **strong-extensibility** Golang RPC framework that helps developers build microservices. If the performance and extensibility are the main concerns when you develop microservices, Kitex can be a good choice.
1516

@@ -107,6 +108,7 @@ Kitex is distributed under the [Apache License, version 2.0](https://github.com/
107108
- Email: [conduct@cloudwego.io](conduct@cloudwego.io)
108109
- How to become a member: [COMMUNITY MEMBERSHIP](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md)
109110
- Issues: [Issues](https://github.com/cloudwego/kitex/issues)
111+
- Slack: Join our CloudWeGo community [Slack Channel](https://join.slack.com/t/cloudwego/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA).
110112
- Lark: Scan the QR code below with [Lark](https://www.larksuite.com/zh_cn/download) to join our CloudWeGo/kitex user group.
111113

112114
![LarkGroup](images/lark_group.png)

README_cn.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[![ClosedIssue](https://img.shields.io/github/issues-closed/cloudwego/kitex)](https://github.com/cloudwego/kitex/issues?q=is%3Aissue+is%3Aclosed)
1111
![Stars](https://img.shields.io/github/stars/cloudwego/kitex)
1212
![Forks](https://img.shields.io/github/forks/cloudwego/kitex)
13+
[![Slack](https://img.shields.io/badge/slack-join_chat-success.svg?logo=slack)](https://cloudwego.slack.com/join/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA)
1314

1415
Kitex[kaɪt'eks] 字节跳动内部的 Golang 微服务 RPC 框架,具有**高性能****强可扩展**的特点,在字节内部已广泛使用。如今越来越多的微服务选择使用 Golang,如果对微服务性能有要求,又希望定制扩展融入自己的治理体系,Kitex 会是一个不错的选择。
1516

@@ -105,6 +106,7 @@ Kitex 基于[Apache License 2.0](LICENSE) 许可证,其依赖的三方组件
105106
- Email: conduct@cloudwego.io
106107
- 如何成为 member: [COMMUNITY MEMBERSHIP](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md)
107108
- Issues: [Issues](https://github.com/cloudwego/kitex/issues)
109+
- Slack: 加入我们的 [Slack 频道](https://join.slack.com/t/cloudwego/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA)
108110
- 飞书用户群([注册飞书](https://www.feishu.cn/)进群)
109111

110112
![LarkGroup](images/lark_group_cn.png)

client/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ type kcFinalizerClient struct {
8181
*kClient
8282
}
8383

84+
func (kf *kcFinalizerClient) Call(ctx context.Context, method string, request, response interface{}) error {
85+
defer runtime.KeepAlive(kf)
86+
return kf.kClient.Call(ctx, method, request, response)
87+
}
88+
8489
// NewClient creates a kitex.Client with the given ServiceInfo, it is from generated code.
8590
func NewClient(svcInfo *serviceinfo.ServiceInfo, opts ...Option) (Client, error) {
8691
if svcInfo == nil {
@@ -90,6 +95,7 @@ func NewClient(svcInfo *serviceinfo.ServiceInfo, opts ...Option) (Client, error)
9095
kc.svcInfo = svcInfo
9196
kc.opt = client.NewOptions(opts)
9297
if err := kc.init(); err != nil {
98+
_ = kc.Close()
9399
return nil, err
94100
}
95101
// like os.File, if kc is garbage-collected, but Close is not called, call Close.
@@ -184,6 +190,10 @@ func (kc *kClient) initProxy() error {
184190
// update fields in the client option for further use.
185191
kc.opt.Resolver = cfg.Resolver
186192
kc.opt.Balancer = cfg.Balancer
193+
// close predefined pool when proxy init new pool.
194+
if cfg.Pool != kc.opt.RemoteOpt.ConnPool && kc.opt.RemoteOpt.ConnPool != nil {
195+
kc.opt.RemoteOpt.ConnPool.Close()
196+
}
187197
kc.opt.RemoteOpt.ConnPool = cfg.Pool
188198
kc.opt.Targets = cfg.FixedTargets
189199
}

client/client_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,18 +546,34 @@ func TestClientFinalizer(t *testing.T) {
546546
runtime.ReadMemStats(&ms)
547547
t.Logf("Before new clients, allocation: %f Mb, Number of allocation: %d\n", mb(ms.HeapAlloc), ms.HeapObjects)
548548

549-
var closeCalledCnt int32
550-
cliCnt := 1000
549+
var (
550+
closeCalledCnt int32
551+
succeedCnt = 10000
552+
failedCnt = 10000
553+
cliCnt = succeedCnt + failedCnt
554+
)
551555
clis := make([]Client, cliCnt)
552-
for i := 0; i < cliCnt; i++ {
556+
// clients that init successfully.
557+
for i := 0; i < succeedCnt; i++ {
553558
svcInfo := mocks.ServiceInfo()
554-
mockClient, err := NewClient(svcInfo, WithDestService("destService"), WithCloseCallbacks(func() error {
555-
atomic.AddInt32(&closeCalledCnt, 1)
556-
return nil
557-
}))
559+
mockClient, err := NewClient(svcInfo, WithDestService("destService"), WithShortConnection(),
560+
WithCloseCallbacks(func() error {
561+
atomic.AddInt32(&closeCalledCnt, 1)
562+
return nil
563+
}))
558564
test.Assert(t, err == nil, err)
559565
clis[i] = mockClient
560566
}
567+
// clients that init failed, closeCallback should be called
568+
for i := succeedCnt; i < cliCnt; i++ {
569+
mockClient, err := NewClient(svcInfo, WithDestService(""), WithShortConnection(),
570+
WithCloseCallbacks(func() error {
571+
atomic.AddInt32(&closeCalledCnt, 1)
572+
return nil
573+
}))
574+
test.Assert(t, err != nil, err)
575+
clis[i] = mockClient
576+
}
561577

562578
runtime.ReadMemStats(&ms)
563579
t.Logf("After new clients, allocation: %f Mb, Number of allocation: %d\n", mb(ms.HeapAlloc), ms.HeapObjects)

client/option_advanced.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package client
2121

2222
import (
2323
"fmt"
24+
"reflect"
2425

2526
"github.com/cloudwego/kitex/internal/client"
2627
"github.com/cloudwego/kitex/pkg/acl"
@@ -49,7 +50,6 @@ func WithHTTPConnection() Option {
4950
// WithClientBasicInfo provides initial information for client endpoint in RPCInfo.
5051
func WithClientBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option {
5152
return Option{F: func(o *client.Options, di *utils.Slice) {
52-
o.Once.OnceOrPanic()
5353
di.Push(fmt.Sprintf("WithClientBasicInfo(%+v)", ebi))
5454
if ebi != nil {
5555
o.Cli = ebi
@@ -206,6 +206,28 @@ func WithBoundHandler(h remote.BoundHandler) Option {
206206
return Option{F: func(o *client.Options, di *utils.Slice) {
207207
di.Push(fmt.Sprintf("AddBoundHandler(%T)", h))
208208

209-
o.RemoteOpt.AppendBoundHandler(h)
209+
exist := false
210+
switch handler := h.(type) {
211+
case remote.InboundHandler:
212+
for _, inboundHandler := range o.RemoteOpt.Inbounds {
213+
if reflect.DeepEqual(inboundHandler, handler) {
214+
exist = true
215+
break
216+
}
217+
}
218+
case remote.OutboundHandler:
219+
for _, outboundHandler := range o.RemoteOpt.Outbounds {
220+
if reflect.DeepEqual(outboundHandler, handler) {
221+
exist = true
222+
break
223+
}
224+
}
225+
}
226+
// prevent duplication
227+
if !exist {
228+
o.RemoteOpt.AppendBoundHandler(h)
229+
} else {
230+
klog.Warnf("KITEX: BoundHandler already exists, BoundHandler=%v", h)
231+
}
210232
}}
211233
}

client/option_test.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,20 @@ func TestForwardProxy(t *testing.T) {
152152
opts = append(opts, WithProxy(fp))
153153

154154
svcInfo := mocks.ServiceInfo()
155+
// Configure long pool and check if the pool is closed when initProxy
156+
// If the proxy does not configure pool, use the predefined pool
157+
mockLongPool := mock_remote.NewMockLongConnPool(ctrl)
158+
var closed bool
159+
mockLongPool.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(mocksnetpoll.NewMockConnection(ctrl), nil).Times(1)
160+
mockLongPool.EXPECT().Close().Do(func() {
161+
closed = true
162+
}).AnyTimes()
163+
mockLongPool.EXPECT().Put(gomock.Any()).Return(nil).AnyTimes()
164+
mockLongPool.EXPECT().Discard(gomock.Any()).Return(nil).AnyTimes()
165+
opts = append(opts, WithConnPool(mockLongPool))
155166
cli, err := NewClient(svcInfo, opts...)
156167
test.Assert(t, err == nil)
157-
168+
test.Assert(t, !closed)
158169
mtd := mocks.MockMethod
159170
ctx := context.Background()
160171
req := new(MockTStruct)
@@ -328,13 +339,23 @@ func TestProxyWithConnPool(t *testing.T) {
328339
opts = append(opts, WithTransHandlerFactory(newMockCliTransHandlerFactory(ctrl)))
329340
opts = append(opts, WithDestService("destService"))
330341
opts = append(opts, WithProxy(fp))
331-
opts = append(opts, WithConnPool(&mockLongConnPool{mock_remote.NewMockLongConnPool(ctrl), mock_remote.NewMockConnPoolReporter(ctrl)}))
332342
opts = append(opts, WithConnReporterEnabled())
333343
opts = append(opts, WithResolver(resolver404(ctrl)))
344+
// Preconfigured longConnPool should be closed because the proxy configured the pool
345+
mockLongPool := mock_remote.NewMockLongConnPool(ctrl)
346+
var closed bool
347+
mockLongPool.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(mocksnetpoll.NewMockConnection(ctrl), nil).Times(0)
348+
mockLongPool.EXPECT().Close().Do(func() {
349+
closed = true
350+
}).AnyTimes()
351+
mockLongPool.EXPECT().Put(gomock.Any()).Return(nil).AnyTimes()
352+
mockLongPool.EXPECT().Discard(gomock.Any()).Return(nil).AnyTimes()
353+
opts = append(opts, WithConnPool(mockLongPool))
334354

335355
svcInfo := mocks.ServiceInfo()
336356
cli, err := NewClient(svcInfo, opts...)
337357
test.Assert(t, err == nil)
358+
test.Assert(t, closed) // should be true
338359

339360
mtd := mocks.MockMethod
340361
ctx := context.Background()
@@ -556,10 +577,41 @@ func TestWithBoundHandler(t *testing.T) {
556577
ctrl := gomock.NewController(t)
557578
defer ctrl.Finish()
558579

580+
mockInboundHandler := mock_remote.NewMockInboundHandler(ctrl)
581+
opts := client.NewOptions([]client.Option{WithBoundHandler(mockInboundHandler)})
582+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 0)
583+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 1)
584+
585+
opts = client.NewOptions([]client.Option{WithBoundHandler(mockInboundHandler), WithBoundHandler(mockInboundHandler)})
586+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 0)
587+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 1)
588+
589+
mockInboundHandler2 := mock_remote.NewMockInboundHandler(ctrl)
590+
opts = client.NewOptions([]client.Option{WithBoundHandler(mockInboundHandler), WithBoundHandler(mockInboundHandler2)})
591+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 0)
592+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 1)
593+
559594
mockOutboundHandler := mock_remote.NewMockOutboundHandler(ctrl)
560-
opts := client.NewOptions([]client.Option{WithBoundHandler(mockOutboundHandler)})
561-
test.Assert(t, len(opts.RemoteOpt.Outbounds) > 0)
595+
opts = client.NewOptions([]client.Option{WithBoundHandler(mockOutboundHandler)})
596+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 1)
562597
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 0)
598+
599+
opts = client.NewOptions(
600+
[]client.Option{WithBoundHandler(mockOutboundHandler), WithBoundHandler(mockOutboundHandler)})
601+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 1)
602+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 0)
603+
604+
mockOutboundHandler2 := mock_remote.NewMockOutboundHandler(ctrl)
605+
opts = client.NewOptions([]client.Option{
606+
WithBoundHandler(mockOutboundHandler), WithBoundHandler(mockOutboundHandler2),
607+
})
608+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 1)
609+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 0)
610+
611+
mockDuplexBoundHandler := mock_remote.NewMockDuplexBoundHandler(ctrl)
612+
opts = client.NewOptions([]client.Option{WithBoundHandler(mockDuplexBoundHandler), WithBoundHandler(mockDuplexBoundHandler)})
613+
test.Assert(t, len(opts.RemoteOpt.Outbounds) == 1)
614+
test.Assert(t, len(opts.RemoteOpt.Inbounds) == 1)
563615
}
564616

565617
// collection of options

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ go 1.13
55
require (
66
github.com/apache/thrift v0.13.0
77
github.com/bytedance/gopkg v0.0.0-20220531084716-665b4f21126f
8-
github.com/bytedance/mockey v1.0.0-rc.0
98
github.com/choleraehyq/pid v0.0.15
10-
github.com/cloudwego/fastpb v0.0.2
9+
github.com/cloudwego/fastpb v0.0.3
1110
github.com/cloudwego/frugal v0.1.3
12-
github.com/cloudwego/netpoll v0.2.6
13-
github.com/cloudwego/thriftgo v0.2.1
11+
github.com/cloudwego/netpoll v0.3.1
12+
github.com/cloudwego/thriftgo v0.2.4
1413
github.com/golang/mock v1.6.0
1514
github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3
1615
github.com/jhump/protoreflect v1.8.2
@@ -21,6 +20,6 @@ require (
2120
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2
2221
golang.org/x/tools v0.1.1
2322
google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384
24-
google.golang.org/protobuf v1.28.0
23+
google.golang.org/protobuf v1.28.1
2524
gopkg.in/yaml.v3 v3.0.1
2625
)

0 commit comments

Comments
 (0)