Open tubzby opened 6 months ago
代码上怎么写的呢?直接用的 example 吗
@e1732a364fed run the example first, it can read/write to the tun interface, anything other than that should be your own job.
@e1732a364fed run the example first, it can read/write to the tun interface, anything other than that should be your own job.
我是在问,你这个 memory leak 的issue 是由什么代码造成的。你没理解我的意思。比如说,example 的代码是不是就会有你这个 issue 的问题
@e1732a364fed run the example first, it can read/write to the tun interface, anything other than that should be your own job.
为什么理解中文如此难呢?你的截图中有中文
@e1732a364fed run the example first, it can read/write to the tun interface, anything other than that should be your own job.
我是在问,你这个 memory leak 的issue 是由什么代码造成的。你没理解我的意思。比如说,example 的代码是不是就会有你这个 issue 的问题
不是example代码,按照自己的需要加的,我看能不能提供一个能重现问题的mini-example
内存泄露,有定位到具体原因吗
这个地方需要判断cached大小,然后在处理数据(图中直接丢弃),否则程序会崩溃
一直没有处理,我这里不会崩溃,只是内存泄漏。
把这段删掉就好了,感觉是造成了tokio泄露了
我也感觉这个地方有问题,一直会启动线程。
Got the time to look into this lately, the problem is that Queue::poll_read
will fork a new thread if no data is ready, but there might be another thread already polling, which may result in a bunch of threads all stuck in polling, cause a memory leak.
The fix is simple, check if the polling thread is running before creating.
The most important thing is that Queue::poll_read
might fired multiple times even if the previous poll_read
is in Poll::Pending
state.
loop {
// in this case, Queue::poll_read will fire once no more than 10ms, even if no data is available.
tokio::select!{
_ = sleep_10ms() => {},
msg = dev.next() => {},
}
}
I'm using the latest version
0.6.1
(asyn api) on Windows, quickly after I finished my code and tested it on Windows 11, I noticed that the memory consumption continued to increase(over 1MB increase in 1 second) and never got freed, so I used Visual Studio to detach to the process and take several memory snapshots to take a close look into this, please check the attached images, from my prospect of view, it's likely coming fromwintun
crate or evenwindows
crate, can anybody look into this?