Skip to content

Conversation

patterniha
Copy link
Collaborator

@patterniha patterniha commented Aug 22, 2025

#5043 (comment)

simplified and optimize UDP dispatcher code.
also, after closing connEntry, it's timer was still active and was not canceled, and i fix that.

@patterniha patterniha changed the title UDP dispatcher: simplified and optimized UDP dispatcher: simplified and optimized, cancel connEntry timer after it is closed Aug 22, 2025
@patterniha patterniha force-pushed the udp-dispatcher branch 6 times, most recently from 97f8e6a to 6af9a62 Compare August 23, 2025 03:35
@patterniha patterniha changed the title UDP dispatcher: simplified and optimized, cancel connEntry timer after it is closed Trojan uot: fix memory leak; UDP dispatcher: simplified and optimized Aug 23, 2025
@patterniha
Copy link
Collaborator Author

patterniha commented Aug 23, 2025

Also, probably, the memory leak problem solved in 6af9a62.

we should release buffers, after we're done with them, but we didn't do that in trojan-uot and udp-dns.

@patterniha patterniha changed the title Trojan uot: fix memory leak; UDP dispatcher: simplified and optimized Trojan-uot & UDP-nameserver: fix memory leak; UDP dispatcher: simplified and optimized Aug 23, 2025
@Fangliding
Copy link
Member

又在瞎猜了
1 bug是新版本出现的
2 忘记release不会导致leak 它只是把buffer返还给复用池 就算不还的话会被gc回收的

@patterniha
Copy link
Collaborator Author

patterniha commented Aug 23, 2025

also, this matches the pprof chart:
freedom-ReadMultiBuffer -> udp-dispatcher-handleInput-callback -> trojan-handleUDPPayload-NewDispatcher-WriteMultiBuffer

my guess is that the memory leak problem is solved, anyway, this is clearly forgotten-release-buffer and should be fixed.

@kastov I am waiting for your confirm

@patterniha patterniha changed the title Trojan-uot & UDP-nameserver: fix memory leak; UDP dispatcher: simplified and optimized Trojan-uot & UDP-nameserver: fix forgotten release buffer; UDP dispatcher: simplified and optimized Aug 23, 2025
@patterniha
Copy link
Collaborator Author

also we should Interrupt(c.link.Writer) instead of Close(c.link.Writer) in udp-dispatcher, because we may have some data in link-cache

@kastov test https://github.com/XTLS/Xray-core/tree/katsov-test

@Fangliding
Copy link
Member

Screenshot_2025-08-23-17-58-28-121_com android chrome-edit
这些稀碎东西能不能在你自己的frok试 别推到主仓库来污染眼球 just-test都来了

@patterniha

This comment was marked as off-topic.

@patterniha patterniha force-pushed the udp-dispatcher branch 2 times, most recently from 4441155 to 3236d73 Compare August 23, 2025 11:55
@kastov
Copy link
Contributor

kastov commented Aug 23, 2025

also we should Interrupt(c.link.Writer) instead of Close(c.link.Writer) in udp-dispatcher, because we may have some data in link-cache

@kastov test https://github.com/XTLS/Xray-core/tree/katsov-test

working on it

@kastov
Copy link
Contributor

kastov commented Aug 23, 2025

Here is also fresh dumps. Current ram usage 5.4GB. Yesterday was 3.2GB.

Снимок экрана 2025-08-23 в 18 40 21

heap+gor+alloc-23082025.zip

I will relaunch now with core from branch which you provided

@patterniha
Copy link
Collaborator Author

@kastov katsov-test branch updated, please use the new one.

@kastov
Copy link
Contributor

kastov commented Aug 23, 2025

@kastov katsov-test branch updated, please use the new one.

oh, i already started previous one. i believe it is better to keep that one for at least 24 hours to see results

@patterniha
Copy link
Collaborator Author

if possible use new one for 24 h.

@kastov
Copy link
Contributor

kastov commented Aug 23, 2025

@kastov katsov-test branch updated, please use the new one.

btw any ideas how we can stresstest core to see if there any leaks? current way of testing is just so slow... :D

@Fangliding
Copy link
Member

Fangliding commented Aug 24, 2025

Here is also fresh dumps. Current ram usage 5.4GB. Yesterday was 3.2GB.

Снимок экрана 2025-08-23 в 18 40 21 [heap+gor+alloc-23082025.zip](https://github.com/user-attachments/files/21950177/heap%2Bgor%2Balloc-23082025.zip)

I will relaunch now with core from branch which you provided

Try this https://github.com/XTLS/Xray-core/actions/runs/17186238756
Combining two pprofs, I reverted the only most suspicious commit

@kastov
Copy link
Contributor

kastov commented Aug 24, 2025

Hi there! Ram usage: 2.8GB

From branch: https://github.com/XTLS/Xray-core/tree/3236d737f665f99d12ee8c74eb4b86e5a4be1c5d (without last 4 commits).

Src

heap+alloc+gor+24.zip

@kastov
Copy link
Contributor

kastov commented Aug 24, 2025

Try this https://github.com/XTLS/Xray-core/actions/runs/17186238756 Combining two pprofs, I reverted the only most suspicious commit

Working on it

@RPRX
Copy link
Member

RPRX commented Aug 27, 2025

i talk about trojan

Trojan ?那没事了,有爱玩的就自求多福吧,我可不管

@patterniha
Copy link
Collaborator Author

patterniha commented Aug 27, 2025

first, this PR should be merged: #5050 (comment)

second, If you give me one day, I'll fix the trojan-uot-problem for the new version.

third, @Fangliding why you disable default-inbound-tcp-keepAlive???

@RPRX
Copy link
Member

RPRX commented Aug 27, 2025

纠正一下

// Get selects an arbitrary item from the [Pool], removes it from the
// Pool, and returns it to the caller.

Get() 后不 Put() 会被 GC,只是没起到 pool 的作用

@patterniha
Copy link
Collaborator Author

there is no need for one day, i find a easy way, i fix it soon.

@Fangliding
Copy link
Member

Fangliding commented Aug 27, 2025

first, this PR should be merged: #5050 (comment)

second, If you give me one day, I'll fix the trojan-uot-problem for the new version.

third, @Fangliding why you disable default-inbound-tcp-keepAlive???

因为参考的nginx没开 服务端就算不开应该还是有 connIdle 来管 不过Trojan uot好像没有正确实现 connIdle。。

@patterniha
Copy link
Collaborator Author

However, the Trojan uot does not seem to implement connIdle correctly.

yes, this is the reason, and i fix it in: #5064

@artoor32
Copy link

Also, Shadowsocks 2022 has this memory leak issue #3131 . Does this PR fix the problem in Shadowsocks as well?

@patterniha
Copy link
Collaborator Author

Also, Shadowsocks 2022 has this memory leak issue #3131 . Does this PR fix the problem in Shadowsocks as well?

first, #5064, fix the trojan memory leak problem, this is just some refines and i found them during searching of main problem.

second, no, i just modify trojan code.

RPRX and others added 4 commits August 28, 2025 04:55
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.11.0 to 1.11.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.11.0...v1.11.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-version: 1.11.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@patterniha
Copy link
Collaborator Author

@RPRX

this PR need rebase, wait...

@RPRX
Copy link
Member

RPRX commented Aug 29, 2025

第 1500 个 commit 留给你

@patterniha
Copy link
Collaborator Author

READY.

@RPRX RPRX changed the title Trojan-uot & UDP-nameserver: fix forgotten release buffer; UDP dispatcher: simplified and optimized Trojan-UoT & UDP-nameserver: Fix forgotten release buffer; UDP dispatcher: Simplified and optimized Aug 29, 2025
@RPRX RPRX merged commit 593eded into main Aug 29, 2025
75 of 78 checks passed
@patterniha patterniha deleted the udp-dispatcher branch August 29, 2025 15:01
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.

6 participants