Skip to content

Commit a40f5d3

Browse files
authored
feat: release kitex v0.15.1 (#1428)
1 parent f3396ab commit a40f5d3

8 files changed

Lines changed: 615 additions & 27 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "Kitex Release v0.15.1"
3+
linkTitle: "Release v0.15.1"
4+
projects: ["Kitex"]
5+
date: 2025-09-29
6+
description: >
7+
---
8+
9+
## **Introduction to Key Changes**
10+
11+
### **Announcements**
12+
1. **Go Version Support Changes**: Kitex's minimum declared Go version has been adjusted to Go1.20 and supports up to Go1.25
13+
- Currently does not affect Go v1.18/v1.19 compilation, but after being declared for higher versions, subsequent versions will introduce features of higher versions
14+
15+
### **New Features**
16+
1. **Generic Call: New v2 API Supporting Multi-Services and Streaming Calls**
17+
18+
The Thrift binary generic call API now provides v2 version, supporting multi-services and streaming calls. For detailed usage, see [Generic Call User Guide](/docs/kitex/tutorials/advanced-feature/generic-call/basic_usage)
19+
20+
2. **Generic Call: Support for Unknown Service Handler**
21+
22+
Facilitates rapid development of streaming proxy, see [Proxy Application Development Guide](/docs/kitex/tutorials/advanced-feature/proxy_application_development) for details
23+
24+
3. **Generic Call: Support for Server-Level JSON/Map Streaming Generic Calls**
25+
26+
See: [Generic Call User Guide](/docs/kitex/tutorials/advanced-feature/generic-call/basic_usage) for details
27+
28+
4. **TTHeader Streaming: Support for ctx Cancel to Control Flow Lifecycle**
29+
30+
- Quickly terminate streaming calls, saving model resources
31+
- Aligns with gRPC, for detailed usage see [Stream Lifecycle Control Best Practices](/docs/kitex/tutorials/basic-feature/streamx/StreamX_Lifecycle_Control)
32+
- Supports Client actively invoking cancel to end streaming calls
33+
- Supports Client sensing the ctx cancel signal of the current Handler and cascading to end streaming calls
34+
35+
5. **Streaming Error Handling Optimization**
36+
37+
- Quickly address specific error scenarios, accelerate troubleshooting of cascade cancel link issues, see [Stream Error Handling Best Practices](/docs/kitex/tutorials/basic-feature/streamx/StreamX_Error_Handling) for details
38+
- In cascade cancel scenarios, error description includes complete cancel link, quickly locating the first-hop service that actively cancels
39+
- Error description includes specific error scenarios and corresponding unique error codes
40+
- Unified and convenient cancel error handling method, eliminating the need for cumbersome string matching
41+
42+
### **Feature/Experience Optimization**
43+
1. **Generic Client: Optimize Background Goroutine Startup Logic**
44+
45+
Starting from Kitex v0.13.0, a generic client supports both Ping-Pong and streaming calls, and uses the TTHeader Streaming protocol by default. Each generic client automatically starts a background goroutine to clean up idle connections for TTHeader Streaming.
46+
47+
If users previously used the generic client incorrectly (e.g., creating a generic client for each request), upgrading to Kitex v0.13.x would result in a large number of background goroutines being created, leading to goroutine leaks, even though streaming generics are not actually used.
48+
49+
The v0.15.1 version only creates background goroutines when streaming generalization is actually used.
50+
51+
### **Code Generation Tool Kitex Tool**
52+
1. **Strict Enum Value Checking**
53+
54+
For scenarios where Thrift IDL defines enum value overflow, strict generation checks have been added, see [Kitex Tool Enum Type Checking Instructions](/docs/kitex/tutorials/code-gen/idl_enumeration_type) for details
55+
56+
This change will cause some products to fail to generate because correctness already has issues, posing a significant risk to the service!
57+
58+
### **Special Change - Minor Services May Be Affected**
59+
> Interface Breaking Change that has no impact on 99.9% of users
60+
61+
Kitex will ensure compatibility with normal usage patterns of internal users. However, individual users may have dependencies on definitions in the Kitex repository, and this version adjustment of Kitex will have an impact on these users.
62+
63+
This version has made minor adjustments to non-standard usage of `remote.Message`, `rpcinfo.RPCInfo` or `generic.Generic` interfaces. If there are special usages, they need to be adjusted to conform to the new version's interface definition.
64+
65+
## **Full Change**
66+
67+
### Feature
68+
* feat(ttstream): support ctx cancel and detailed canceled error by @DMwangnima in [#1821](https://github.com/cloudwego/kitex/pull/1821) | [#1859](https://github.com/cloudwego/kitex/pull/1859) | [#1856](https://github.com/cloudwego/kitex/pull/1856)
69+
* feat(generic): support new thrift binary generic call api, server streaming generic call and unknown service or method handler by @jayantxie in [#1837](https://github.com/cloudwego/kitex/pull/1837) | [#1857](https://github.com/cloudwego/kitex/pull/1857)
70+
* feat(grpc): support dump MaxConcurrentStreams of HTTP2 Client by @DMwangnima in [#1820](https://github.com/cloudwego/kitex/pull/1820)
71+
72+
### Fix
73+
* fix(retry): shallow copy response to avoid data race by @jayantxie in [#1799](https://github.com/cloudwego/kitex/pull/1799) | [#1814](https://github.com/cloudwego/kitex/pull/1814)
74+
* fix(lbcache): check the existence before new Balancer to prevent leakage by @ppzqh in [#1825](https://github.com/cloudwego/kitex/pull/1825)
75+
* fix(generic): descriptor.HTTPRequest.GetParam nil pointer exception by @jayantxie in [#1827](https://github.com/cloudwego/kitex/pull/1827)
76+
* fix(generic): fix generic write int range check by @HeyJavaBean in [#1861](https://github.com/cloudwego/kitex/pull/1861)
77+
* fix(rpcinfo): protect bizErr and extra field of ri.Invocation by lock by @jayantxie in [#1850](https://github.com/cloudwego/kitex/pull/1850)
78+
* fix(timeout): remove timer pool to avoid timer race issue by @jayantxie in [#1858](https://github.com/cloudwego/kitex/pull/1858)
79+
* fix(tool): disable fast api for protobuf by @DMwangnima in [#1807](https://github.com/cloudwego/kitex/pull/1807)
80+
* fix(tool): skip pb code gen for arg -use by @xiaost in [#1819](https://github.com/cloudwego/kitex/pull/1819)
81+
82+
### Optimize
83+
* optimize(grpc): access metadata.MD without ToLower by @xiaost in [#1806](https://github.com/cloudwego/kitex/pull/1806)
84+
* optimize(ttstream): lazy init cleaning task for ObjectPool to reduce the impact of lots of goroutines caused by creating too many Generic Client by @DMwangnima in [#1842](https://github.com/cloudwego/kitex/pull/1842)
85+
* optimize(tool): remove string deepcopy because the string type is read-only in Go by @jayantxie in [#1832](https://github.com/cloudwego/kitex/pull/1832)
86+
87+
### Refactor
88+
* refactor(ttstream): remove ttstream provider by @jayantxie in [#1805](https://github.com/cloudwego/kitex/pull/1805)
89+
* refactor(rpcinfo): move service/method info from message to rpcinfo, remove protocol info from message and update min go version to 1.20 by @jayantxie in [#1818](https://github.com/cloudwego/kitex/pull/1818) | [#1855](https://github.com/cloudwego/kitex/pull/1855)
90+
* refactor(server): remove service middleware and SupportedTransportsFunc api by @jayantxie in [#1839](https://github.com/cloudwego/kitex/pull/1839)
91+
* refactor(server): remove useless TargetSvcInfo field by @jayantxie in [#1840](https://github.com/cloudwego/kitex/pull/1840)
92+
93+
### Chore
94+
* chore: update dependencies of kitex to support go 1.25 and new features by @jayantxie @AsterDY in [#1848](https://github.com/cloudwego/kitex/pull/1848) | [#1834](https://github.com/cloudwego/kitex/pull/1834) | [#1862](https://github.com/cloudwego/kitex/pull/1862) | [#1836](https://github.com/cloudwego/kitex/pull/1836)
95+
* chore: update version v0.15.0 by @jayantxie in [#1864](https://github.com/cloudwego/kitex/pull/1864)
96+
* docs: fix broken link to blogs by @scientiacoder in [#1813](https://github.com/cloudwego/kitex/pull/1813)
97+
* chore: support custom ctx key to pass to downstream in Service-Inline by @Duslia in [#1709](https://github.com/cloudwego/kitex/pull/1709)

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Error_Handling.md

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,73 @@
11
---
2-
title: "StreamX Error Handling"
3-
date: 2025-01-13
4-
weight: 4
5-
keywords: ["Stream Error Handling"]
6-
description: ""
2+
title: "Stream Error Handling Best Practices"
3+
linkTitle: "Stream Error Handling Best Practices"
4+
weight: 3
5+
date: 2025-09-29
6+
description: "Kitex StreamX stream error handling best practices, introducing TTHeader Streaming error codes and error handling mechanisms."
77
---
88

99
## Preface
1010

11-
Unlike RPC, stream errors can occur at any time during stream processing. For example, a server can return an error after sending multiple messages. However, once a stream has sent an error, it cannot send any more messages.
11+
Unlike PingPong RPC, stream errors can occur at any time during stream processing. For example, a server can return an error after sending multiple messages. However, once a stream has sent an error, it cannot send any more messages.
1212

13-
## Error type
13+
## Error Types
1414

15-
### Business exception
15+
### Framework Exceptions
1616

17-
**Usage example** : For example, in the ChatGPT scenario, we need to constantly check whether the user account balance can continue to call the large model to generate returns.
17+
#### Error Description Meaning
1818

19-
Server implementation:
19+
```
20+
[ttstream error, code=12007] [server-side stream] [canceled path: ServiceA] user code invoking stream RPC with context processed by context.WithCancel or context.WithTimeout, then invoking cancel() actively
21+
```
22+
23+
| Error Description | Meaning | Notes |
24+
|-------------------|---------|-------|
25+
| [ttstream error, code=12007] | TTHeader Streaming error, error code 12007, corresponding to the scenario where upstream actively cancels | |
26+
| [server-side stream] | Indicates that the error is thrown by the Stream on the server side | |
27+
| [canceled path: ServiceA] | Indicates that ServiceA actively initiated cancel | |
28+
| user code invoking stream RPC with context processed by context.WithCancel or context.WithTimeout, then invoking cancel() actively | Specific error description | |
29+
30+
#### Error Code Summary
31+
32+
TTHeader Streaming Error Summary
33+
34+
| Error Code | Error Description | Meaning | Notes |
35+
|------------|-------------------|---------|-------|
36+
| 12001 | application exception | Business exception, downstream handler returns err | |
37+
| 12002 | unexpected header frame | Header Frame related errors | |
38+
| 12003 | illegal biz err | Failed to parse business exception contained in Trailer Frame | |
39+
| 12004 | illegal frame | Failed to parse basic information of Frame | |
40+
| 12005 | illegal operation | Error due to improper Stream usage, such as Stream has been CloseSend but still Send | |
41+
| 12006 | transport is closing | Connection exception, such as connection has been closed | |
42+
| 12007 | user code invoking stream RPC with context processed by context.WithCancel or context.WithTimeout, then invoking cancel() actively | Upstream actively uses cancel() | |
43+
| 12008 | user code canceled with cancelCause(error) | Upstream uses context.WithCancelCause and actively uses cancel(err) | |
44+
| 12009 | canceled by downstream | Canceled by downstream service | |
45+
| 12010 | canceled by upstream | Canceled by upstream service | |
46+
| 12011 | Internal canceled | Cascade cancel scenario, such as gRPC handler ctx is canceled, cascade cancel TTHeader Streaming | |
47+
| 12012 | canceled by business handler returning | Handler exits early, but there are still asynchronous goroutines using Recv/Send | |
48+
| 12013 | canceled by connection closed | Stream lifecycle ends due to connection closure, common in server-side service migration/update | |
49+
50+
### Business Exceptions
51+
52+
Usage example: For example, in the ChatGPT scenario, we need to constantly check whether the user account balance can continue to call the large model to generate returns.
53+
54+
**Server Implementation:**
2055

2156
```go
2257
func (si *streamingService) ServerStreamWithErr(ctx context.Context, req *echo.Request, stream echo.TestService_ServerStreamWithErrServer) error {
23-
// 检查用户账户余额
58+
// Check user account balance
2459
for isHasBalance (req.UserId) {
2560
stream.Send(ctx, res)
2661
}
27-
// 返回用户余额不足错误
62+
// Return insufficient user balance error
2863
bizErr := kerrors.NewBizStatusErrorWithExtra(
2964
10001, "insufficient user balance", map[string]string{"testKey": "testVal"},
3065
)
3166
return bizErr
3267
}
3368
```
3469

35-
Client implementation:
70+
**Client Implementation:**
3671

3772
```go
3873
stream, err = cli.ServerStreamWithErr(ctx, req)
@@ -50,11 +85,11 @@ if ok {
5085
}
5186
```
5287

53-
### Other errors
88+
### Other Errors
5489

5590
If the Error returned by the Server is a non-business exception, the framework will be uniformly encapsulated as `(*thrift.ApplicationException)`. At this time, only the error Message can be obtained.
5691

57-
Server implementation:
92+
**Server Implementation:**
5893

5994
```go
6095
func (si *streamingService) ServerStreamWithErr(ctx context.Context, req *echo.Request, stream echo.TestService_ServerStreamWithErrServer) error {
@@ -63,7 +98,7 @@ func (si *streamingService) ServerStreamWithErr(ctx context.Context, req *echo.R
6398
}
6499
```
65100

66-
Client implementation:
101+
**Client Implementation:**
67102

68103
```go
69104
stream, err = cli.ServerStreamWithErr(ctx, req)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "Stream Lifecycle Control Best Practices"
3+
linkTitle: "Stream Lifecycle Control Best Practices"
4+
weight: 4
5+
date: 2025-09-29
6+
description: "Kitex StreamX stream lifecycle control best practices, introducing how to use ctx cancel to control streaming call lifecycle."
7+
---
8+
9+
## Background
10+
11+
When directly interacting with the model layer through streaming, the caller needs to directly notify the model layer to stop responding in certain scenarios, thereby saving model resources.
12+
13+
In large model application scenarios such as classic Chat, the entire chain uses streaming interfaces that need to be connected in series, requiring perception of end-user disconnection signals and quickly ending the entire chain.
14+
15+
The above scenarios essentially require the upstream to be able to actively end streaming calls, often using ctx for control. When ctx is canceled, the Stream lifecycle will also end.
16+
17+
Kitex gRPC and TTHeader Streaming both support the mechanism of controlling Stream lifecycle based on ctx cancel, and TTHeader Streaming optimizes error descriptions on the basis of gRPC, which can better handle problem diagnosis in cascade cancel scenarios.
18+
19+
## TTHeader Streaming Supports Stream Lifecycle Control Based on ctx cancel
20+
21+
**Kitex >= v0.15.1 supports this feature**
22+
23+
### Upstream Actively Cancels Downstream
24+
25+
Here we use ServerStreaming as an example. When the upstream receives a special response, it actively calls cancel() to end the downstream Stream lifecycle.
26+
27+
#### Upstream - ServiceA
28+
29+
```go
30+
// ctx generally comes from handler
31+
ctx, cancel := context.WithCancel(ctx)
32+
defer cancel()
33+
cliSt, err := cli.InvokeStreaming(ctx, req)
34+
if err != nil {
35+
// Log or perform other operations
36+
return
37+
}
38+
39+
for {
40+
resp, err := cliSt.Recv(cliSt.Context())
41+
if err != nil {
42+
if err == io.EOF {
43+
// Normal end
44+
return
45+
}
46+
// Log or perform other operations
47+
// Abnormal end
48+
return
49+
}
50+
// Determine if it is a business-specific response, for example, a special flag is defined in resp to indicate end
51+
if isBizSpecialResp(resp) {
52+
// Cancel downstream Stream
53+
cancel()
54+
return
55+
}
56+
}
57+
```
58+
59+
#### Downstream - ServiceB
60+
61+
```go
62+
import (
63+
"github.com/cloudwego/kitex/pkg/kerrors"
64+
)
65+
66+
func (impl *ServiceImpl) InvokeStreaming(ctx context.Context, stream Service_InvokeStreamingServer) (err error) {
67+
// Downstream continuously sends data, only for demonstration
68+
for {
69+
if err = stream.Send(ctx, resp); err != nil {
70+
if errors.Is(kerrors.ErrStreamingCanceled, err) {
71+
// Upstream cancel
72+
}
73+
// Log or perform other operations
74+
return
75+
}
76+
time.Sleep(100 * time.Millisecond)
77+
}
78+
}
79+
```
80+
81+
At this time, the downstream error description is:
82+
83+
```
84+
[ttstream error, code=12007] [server-side stream] [canceled path: ServiceA] user code invoking stream RPC with context processed by context.WithCancel or context.WithTimeout, then invoking cancel() actively
85+
```
86+
87+
The meaning of each part of the error description is as follows:
88+
89+
| Error Description | Meaning | Notes |
90+
|-------------------|---------|-------|
91+
| [ttstream error, code=12007] | TTHeader Streaming error, error code 12007, corresponding to the scenario where upstream actively cancels | |
92+
| [server-side stream] | Indicates that the error is thrown by the Stream on the server side | |
93+
| [canceled path: ServiceA] | Indicates that ServiceA actively initiated cancel | |
94+
| user code invoking stream RPC with context processed by context.WithCancel or context.WithTimeout, then invoking cancel() actively | Specific error description | |
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "Kitex Tool Enum Type Checking Instructions"
3+
linkTitle: "Enum Type Checking"
4+
weight: 12
5+
date: 2025-09-29
6+
description: "Kitex Tool enum type checking instructions, introducing the checking mechanism for Thrift IDL enum value overflow issues."
7+
---
8+
9+
## Background: Enum int32 Overflow Issue
10+
11+
In the Thrift protocol, enum types are actually passed as int32. If the Thrift IDL defines enum values that exceed the int32 range, they will overflow during transmission, and the peer cannot receive the correct value and cannot match the correct enum type.
12+
13+
**The correctness already has issues, posing a significant risk to the service!!!**
14+
15+
A common error writing is as follows: (treating enum values as similar to fixed-format error codes, actually overflowing as int32)
16+
17+
```thrift
18+
enum MyEnum{
19+
A = 3000000001000,
20+
B = 3000000001001,
21+
C = 3000000001002,
22+
}
23+
```
24+
25+
## Tool Changes: Strict Correctness Checking
26+
27+
Generally, Goland IDE will not prompt this Thrift syntax issue, but as long as it's written this way, using enums will definitely cause errors.
28+
29+
Therefore, to ensure correctness and avoid risk hazards, Kitex Tool after v0.15.1 (Thriftgo v0.4.3) will check this enum scenario, and when encountering out-of-bounds, it will directly fail to generate and prompt the location:
30+
31+
```
32+
[WARN] enum overflow: the value (3000000001000) of enum 'xxx/base.thrift MyEnum' exceeds the range of int32.
33+
Due to legacy implementation, thriftgo generates int64 for enums in Go code.
34+
However, during network, values undergo int64->int32->int64 conversion. Values outside int32 will overflow.
35+
Please adjust the enum value to fit within the int32 range [-2147483648, 2147483647].
36+
If you just want to define a very big constant, please use 'const i64 MyConst = xxx' instead.
37+
```
38+
39+
This error message indicates that in the `xxx/base.thrift` file, the enum `3000000001000` of `MyEnum` overflows.
40+
41+
## Solution: Correct Incorrect Enum Values
42+
43+
The tool's error message will contain information about the incorrect enum value:
44+
45+
```
46+
enum overflow: the value (3000000001000) of enum 'xxx/base.thrift MyEnum'
47+
```
48+
49+
You need to find the problematic enum value according to the prompt and correct it to within the int32 range (-2147483648, 2147483647).
50+
51+
If this IDL belongs to other public libraries, you can blame the file history and contact the corresponding classmate to modify it.
52+
53+
**This interception check does not support skipping for now**
54+
55+
## Indirect Impact of Dependency Introduction
56+
57+
Sorry, if your IDL introduces illegally defined Enums from others, it will affect your product generation. To eliminate this wrong usage, unified failure handling is applied. Please contact the corresponding IDL definition classmates to modify it.

0 commit comments

Comments
 (0)