Open urish opened 1 year ago
Created a small GitHub repo with a reproduction:
https://github.com/urish/virtualnetwork-leak
It's basically the same code as above, but packaged into a go project for easier reproduction.
Thanks. Sorry for not noticing this earlier, but I will take a look at this.
Thanks!
The code as in the example
for i := 0; i < 1000; i++ {
_, err := virtualnetwork.New(&config)
if err != nil {
panic(err)
}
}
runtime.GC()
just claims a new device and never release, hence an out-of-memory. The queston however is when you want to release it. Opening multiple is allowed and is hold on until released/closed. At what point would you make that decision?
From my point of view, having a Close()
method which would release a VirtualNetwork would be ideal
OK, just to confirm that the issue is about adding additional functionality to deconstruct. :+1
On Fri, Dec 2, 2022 at 2:23 PM Uri Shaked @.***> wrote:
From my point of view, having a Close() method which would release a VirtualNetwork would be ideal
— Reply to this email directly, view it on GitHub https://github.com/containers/gvisor-tap-vsock/issues/161#issuecomment-1334814236, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAOZRUSWCPD3CPBC7JMZDWLGIUTANCNFSM6AAAAAASHPZ3JI . You are receiving this because you were assigned.Message ID: @.***>
--
Gerard Braad | http://gbraad.nl
STEM is the source, but BUILD is how you develop! [ Better Understanding Involves Learning and Doing ]
Yes 😀
Spent some time on this, and most of the memory consumption is coming from VirtualNetwork.stack
which has a Close()
method. However, adding a VirtualNetwork.Close()
with just a call to n.stack.Close()
is not enough as this then results in dozens of ERRO[0000] EOF
being logged. This has to do with what is done in pkg/virtualnetwork.addServices()
as commenting out the call in pkg/virtualnetwork.New()
removes the logs, but I stopped the investigation there for now, easy to get lost in that code :-/
will also have to spend more time on this. I see memory leaks on Windows, but they are caused by something else that fails first
Currently, there's no way to free the memory allocated by VirtualNetwork.
For instance, the following code will leak around ~100MB of memory:
Output:
The implementation of memStats() (taken from here):