Skip to content

prevent indefinite defer-close by checking last_active_time#3216

Open
jenrryyou wants to merge 1 commit intoapache:masterfrom
jenrryyou:refine_defer_close_second
Open

prevent indefinite defer-close by checking last_active_time#3216
jenrryyou wants to merge 1 commit intoapache:masterfrom
jenrryyou:refine_defer_close_second

Conversation

@jenrryyou
Copy link
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

在 SocketMap 里决定“是否进入 defer_close 倒计时”时,不再无条件
defer,而是先看该连接最近一次读/写的活跃时间。

• 具体改动:当 ref_count 归零准备移除连接时,只有在“连接最近仍有活跃(last_active_time_us 距今不超过 defer_close_second)”的情况下,才把 no_ref_us
置为当前时间、开始倒计时;如果连接其实已经闲置超过 defer_close_second,则直接从 socket_map 删除并释放 socket 引用(src/brpc/socket_map.cpp:293)。
• 意图:避免老 socket 在“channel 频繁创建/析构导致 ref_count 归零又很快被重新引用”的场景下反复刷新倒计时,从而把一个已经长期不活跃/可能已失败的连接在
socket_map 里拖很久,导致新连接迟迟不创建、请求持续复用老连接并依赖其健康检查重连(进而在重连慢时持续失败)。

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

@wwbmmm
Copy link
Contributor

wwbmmm commented Feb 6, 2026

You have changed the default behavior of SocketMap. Although it may be a better practice, it may cause some side effects to existing users. I suggest to add a new gflag to control this behavior, and update the document about defer_close_second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants