Skip to content

Direct/Freedom outbound: Fix blockDelay for DispatchLink() inbounds such as VLESS, Hysteria, etc. - #7238

Merged
RPRX merged 2 commits into
XTLS:mainfrom
solodecode:freedom-block-delay
Oct 28, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
solodecode:freedom-block-delay

Conversation

@solodecode

Copy link
Copy Markdown
Contributor

Regression from #6060 (958eb9e). blackhole waits for buf.Copy(input, buf.Discard) and relies on the blockDelay timer calling common.Interrupt(input) to end it. That only works for a pipe: VLESS, Hysteria and other inbounds that use DispatchLink pass a reader on the client connection, and Interrupt does nothing to it. So a blocked connection stays open until the client closes it, whatever blockDelay is. In our tests it was still open after 330 s, longer than connIdle.

Drain the input in a goroutine and return once the delay has passed or the input has ended. The inbound then closes the connection, as it does after the blackhole outbound.

TestVlessBlockDelay covers blockDelay 0 and 1 through a VLESS inbound. Both cases fail on main.

… (VLESS, Hysteria, etc.)

blackhole waited for buf.Copy(input, buf.Discard) and relied on the
blockDelay timer calling common.Interrupt(input) to end it. Inbounds that
call DispatchLink (VLESS, Hysteria, SOCKS, HTTP CONNECT, dokodemo-door,
TUN, WireGuard, MASQUE) pass a reader on the client connection, which
Interrupt does not stop, so a blocked connection stayed open until the
client closed it.

Drain the input in a goroutine and return once the delay has passed or
the input has ended. The inbound then closes the client connection.
@Meo597

Meo597 commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

改用 time.After

@solodecode

solodecode commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

switched to time.After

@Meo597 Meo597 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单看黑洞效果和以前是相同的,修的其实是如果客户端静默断开了,connIdle 又没生效,保证到期后强制回收掉连接。

@Meo597

Meo597 commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

再回来看看还是觉得很抽象
common.Interrupt 不保证能 Interrupt

@solodecode

Copy link
Copy Markdown
Contributor Author

再回来看看还是觉得很抽象 common.Interrupt 不保证能 Interrupt

should I drop the Interrupt call there? it doesnt do anything for these inbounds anyway

@Meo597

Meo597 commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

No, they each have their own purpose. Keep it as it is.

@RPRX RPRX changed the title Direct/Freedom outbound: Close blocked connections after blockDelay (VLESS, Hysteria, etc.) Direct/Freedom outbound: Fix blockDelay for DispatchLink() inbounds such as VLESS, Hysteria, etc. Oct 28, 2026
@RPRX

RPRX commented Oct 28, 2026

Copy link
Copy Markdown
Member

@Meo597 Block/Blackhole 出站该并入 Direct/Freedom 出站了,无条件的 "block" 不解析/拨号,也方便用户熟悉 finalRules

@RPRX

RPRX commented Oct 28, 2026

Copy link
Copy Markdown
Member

单看黑洞效果和以前是相同的,修的其实是如果客户端静默断开了,connIdle 又没生效,保证到期后强制回收掉连接。

另外你这说法是不是有点问题,人家都说了新增的 test fails on main,我先按该 PR 的原意图合了

@RPRX
RPRX merged commit 229799a into XTLS:main Oct 28, 2026
45 of 46 checks passed
@Meo597

Meo597 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

客户端静默断开会导致 buf.Copy 一直阻塞
freedom 原有的 connIdle 是在下面几行安装的
原 timer 到期后 common.Interrupt 不保证能 Interrupt 一些协议没实现它
然后就泄露了

现在把 buf.Copy 放到协程
靠 select 阻塞,到点后 freedom.Process 一路返回
dispatchLink 就能 close 了

common.Interrupt 还是太抽象了

@Meo597

Meo597 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

你之前觉得 #6060 (comment)
估计就是这个原因?

@Meo597

Meo597 commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@Meo597 Block/Blackhole 出站该并入 Direct/Freedom 出站了,无条件的 "block" 不解析/拨号,也方便用户熟悉 finalRules

如果用户去配了这个特殊黑洞的 finalrules 呢

@RPRX

RPRX commented Oct 28, 2026

Copy link
Copy Markdown
Member

你之前觉得 #6060 (comment) 估计就是这个原因?

我已经忘了当时的思维逻辑,也懒得重新建立思考,总之现在修了屎山架构导致的这个问题就行,你有兴趣的话直接改架构吧

不过 #7238 (comment) 更重要,更大的好处是用户都会知道 finalRules 了,撤掉 #7240 的 pin 指日可待

如果用户去配了这个特殊黑洞的 finalrules 呢

走现行常规流程,其实除了 IP,其它的判断都能提前,不过代码可能很复杂就算了

话说我依稀记得单写 "allow" 就有特殊处理,这个单写 "block" 是类似的,特殊处理一下就能取代 Block/Blackhole 出站,写吧

@RPRX

RPRX commented Oct 28, 2026

Copy link
Copy Markdown
Member

对了,还需要加个选项 blockReply,类似于 Block/Blackhole 出站的 response 但配置更灵活,或许直接用 fm noise 那一套?

@Meo597

Meo597 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

或许开个新的出站类型,专门用来伪造各种响应之类的
以后还能把 lua 放进来更灵活

finalRules 的黑洞就保持简单?
不然有点违背物理定律了

@Meo597

Meo597 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

我已经忘了当时的思维逻辑,也懒得重新建立思考,总之现在修了屎山架构导致的这个问题就行,你有兴趣的话直接改架构吧

重构的事儿再说吧,相信后 AI 的智慧
Lua 已经严重 delay 再不做估计都快忘干净细节了

Blackhole 比较好弄,我先把这个做了

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.

3 participants