V: Memory Leak on Windows socket recv

Created on 15 Jul 2019  路  7Comments  路  Source: vlang/v

V version: 0.1.14
OS: Windows 10

What did you do?
I ran this code:

import net

fn main() {
server := net.listen(8080)
response := 'HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nHello World\r\n'

for {
    connection := server.accept()
    connection.recv(1024)
    connection.send(response.str, response.len)
    connection.close()
}

}

What did you expect to see?
Webserver should display "Hello World" when I connect to it

What did you see instead?
The webserver did not work as expected and I've seen a huge memory leak

immagine

Bug

Most helpful comment

It should and it will. This is my next project.

All 7 comments

Testing the same code under Linux shows that the webserver does work. When running load test (apache ab) with 10 concurrent connections with 2.5 million requests also shows memory growing (after several runs it uses about 4GB).
It might have to do with the tight for loop so it can't cleanup any resources (?)

The memory has to be cleaned up manually because of the infinite for loop

request = connection.recv(1024)
...
C.free(request)

@justicesuh Yes that fixes it (it stays on a constant 84KB).

Shouldn't the compiler manage such lifetimes or at least warn about the cases it cannot handle?

It should and it will. This is my next project.

@vegax87 did freeing the memory fix the server issue? if not, what browser are you using to connect to the server?

@justicesuh C.free has fixed the memory leak, but there are still 2 issues:
1) the socket isn't opening properly on Windows , because it says "connection refused" on both Firefox and Chrome
1) there's still an anomalous CPU usage around 15% after I try to connect to localhost:8080 ( btw I have 8-core CPU)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PavelVozenilek picture PavelVozenilek  路  3Comments

vtereshkov picture vtereshkov  路  3Comments

penguindark picture penguindark  路  3Comments

choleraehyq picture choleraehyq  路  3Comments

markgraydev picture markgraydev  路  3Comments