Skip to content

veb memory leak #25423

Description

@heyimtcn

Describe the bug

when run memory usage stays at about 150MB even when not being indexed

Reproduction Steps

import veb
import rand
import os
import log
import time
$if get_self ? {
	import net.http
}

struct App {
mut:
	files map[string]u64
}

struct Context {
	veb.Context
}

fn (mut app App) index(mut ctx Context) veb.Result {
	clear_files(mut app)
	now := time.sys_mono_now()
	id := rand.string(25)
	file_path := 'files/${id}.txt'
	os.write_file(file_path,id.repeat(400_000)) or { panic(err) } //10_000_000 (10MB)
	app.files[file_path] = now
	log.debug(gc_heap_usage().str())
	return ctx.file(file_path)
}

fn main() {
	{
		mut l := log.Log{}
		l.set_level(.debug)
		l.set_output_path('log.log')
		l.log_to_console_too()
		log.set_logger(l)
	}
	mut app := &App{}
	os.chdir(os.dir(os.executable()))!
	if !os.exists('files') {
		os.mkdir('files')!
	}
	$if get_self ? {
		spawn fn (mut app App) {
			time.sleep(50 * time.millisecond)
			amount := int($d('get_self_amount',100))
			for i in 0..amount {
				http.get('http://localhost:8080/') or { panic(err) }
				log.info('requested self (${i+1}/${amount})')
				time.sleep($d('get_self_interval',1000) * time.millisecond)
			}
			for {
				log.debug(gc_heap_usage().str())
				clear_files(mut app)
				time.sleep(time.second)
			}
		}(mut app)
	}
	at_exit(fn () {
		os.rmdir_all('files') or { panic(err) }
	})!
	veb.run[App,Context](mut app, 8080)
}

fn clear_files(mut app App) {
	mut files_to_remove := []string{}
	now := time.sys_mono_now()
	for file_path, create_time in app.files {
		if now - create_time >= 2 * time.second {
			files_to_remove << file_path
		}
	}
	for file_path in files_to_remove {
		os.rm(file_path) or { continue }
	}
}
FROM thevlang/vlang:alpine-dev

COPY server.v server.v

RUN v -cc gcc -d get_self -d get_self_interval=100 -d use_openssl server.v

EXPOSE 8080

CMD [ "./server" ]

Expected Behavior

no leaks

Current Behavior

150MB of memory leaked

Possible Solution

No response

Additional Information/Context

this doesn't seem to be handled by the garbage collector, maybe a bug with picoev?

V version

V 0.4.12 e3b915d

Environment details (OS name and version, etc.)

V full version V 0.4.12 9772649.e3b915d
OS windows, Microsoft Windows 11 Pro 26100 64-bit
Processor 16 cpus, 64bit, little endian, AMD Ryzen 7 5800X3D 8-Core Processor
Memory 3.96GB/15.91GB
V executable C:\v\v.exe
V last modified time 2025-09-30 13:29:47
V home dir OK, value: C:\v
VMODULES OK, value: C:\Users\nicof.vmodules
VTMP OK, value: C:\Users\nicof\AppData\Local\Temp\v_0
Current working dir OK, value: C:\Users\nicof\Desktop\reproduce_test
Git version git version 2.51.0.windows.1
V git status weekly.2025.14-897-ge3b915da
.git/config present true
cc version N/A
gcc version gcc (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders, r3) 14.1.0
clang version (built by Brecht Sanders, r3) clang version 18.1.8
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version N/A
glibc version N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Unit: vebBugs/feature requests, that are related to the `veb`, V's official web framework.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions