Skip to content

Commit 3ed9a17

Browse files
committed
doc: upload file 流编程常见问题 QA
1 parent 35e588d commit 3ed9a17

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "流编程常见问题 QA"
3+
date: 2025-01-13
4+
weight: 1
5+
keywords: ["流编程常见问题 QA"]
6+
description: ""
7+
---
8+
9+
## 编程错误导致的问题
10+
11+
### Client 忘记调用 CloseSend
12+
13+
kitex 会在检查用户不再持有 stream 对象时,主动调用一次 CloseSend,避免本端和对端出现流泄漏的情况。
14+
15+
注意,由于检查依赖 GC 时机,所以此时流的延迟监控会显著变大。
16+
17+
### Client 持久化 stream 导致 stream 泄漏
18+
19+
如果用户长期持有 stream 对象,而且不主动调用 stream.CloseSend ,框架会理所应当认为该 stream 还需要被使用,进而不会关闭 stream 以及相关 gorotuine。
20+
21+
### Server 调用 Recv 卡死
22+
23+
如果 client 一直保持一个流活跃,并且一直不调用 CloseSend,stream.Recv() 函数便不会返回。
24+
25+
如果 Server 想要避免 client 用户的错误使用姿势导致自己的问题,可以在 Recv(ctx) 的 ctx 中,定制自己需要的 超时逻辑。例如:
26+
27+
```go
28+
ctx, cancel := context.WithTimeout(ctx, time.Second)
29+
defer cancel()
30+
stream.Recv(ctx)
31+
```
32+
33+
### Server handler 不退出
34+
35+
Server handler 函数退出才标识流的结束,如果用户在这个函数中永远不退出,流也就永远无法结束。

0 commit comments

Comments
 (0)