Skip to content

veb: fix two memory leaks - #26236

Merged
spytheman merged 3 commits into
vlang:masterfrom
fleximus:fix_25423
Jan 2, 2026
Merged

spytheman merged 3 commits into
vlang:masterfrom
fleximus:fix_25423

Conversation

@fleximus

@fleximus fleximus commented Jan 1, 2026

Copy link
Copy Markdown
Member
  1. The veb web framework had a memory leak where response bodies were being cloned multiple times, causing unbounded memory growth under load
  2. Additionally, when veb_livereload was enabled, the first clone was immediately overwritten by response.replace(...), leaking the first allocation

New tests:

  • memory_leak_test.v - Integration test that verifies large responses work correctly
  • memory_leak_test_server.v - Test server with endpoints for heap monitoring and GC collection

Fixes #25423

  1. The veb web framework had a memory leak where response bodies were being cloned multiple times,
     causing unbounded memory growth under load.
  2. Additionally, when `veb_livereload` was enabled, the first clone was immediately overwritten
     by `response.replace(...)`, leaking the first allocation.

New tests:
  - `memory_leak_test.v` - Integration test that verifies large responses work correctly
  - `memory_leak_test_server.v` - Test server with endpoints for heap monitoring and GC collection
@Jengro777

Copy link
Copy Markdown
Contributor

picoev will be replaced by fasthttp.

@fleximus

fleximus commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

picoev will be replaced by fasthttp.

Oh I just saw the 0.5.0 realease πŸ˜ƒ
What will mean it to this fix? Patching the legacy?

@JalonSolov

JalonSolov commented Jan 1, 2026 •

Copy link
Copy Markdown
Collaborator

Looks like these changes are specific to veb, not picoev or fasthttp (which would be lower-level protocol handlers). If this PR is approved, there's no reason not to merge it as-is.

Yes, you did touch picoev, but just to remove commented out lines... no harm, no foul (and arguably should've been done long ago).

Comment thread vlib/veb/tests/memory_leak_test.v Outdated
@spytheman

Copy link
Copy Markdown
Contributor

picoev will be replaced by fasthttp.

Oh I just saw the 0.5.0 realease πŸ˜ƒ What will mean it to this fix? Patching the legacy?

No, this PR is not affected in any way, since we do not do backports to older versions - once they are done, they are immutable.

The fix from this PR, will be merged in the master branch, and will be available right away after that, to people that do v up regularly. It will be available next Monday, for people that download weekly releases (or from the website, which also uses them), and in 2-3 months, when @medvednikov does another versioned release.

@fleximus

fleximus commented Jan 1, 2026

Copy link
Copy Markdown
Member Author

@spytheman what do you think about the failing Docker CI?

@JalonSolov

Copy link
Copy Markdown
Collaborator

Interesting failure... it appears the memory leak that test is looking for is not there with musl libs. That means it's not a V failure, but a libc failure.

Something to be explored...

@spytheman

spytheman commented Jan 1, 2026 •

Copy link
Copy Markdown
Contributor

Add // vtest build: !docker-ubuntu-musl on top of the _test.v file; it most likely can not compile the veb server there (or compiles it without the GC). In both cases, it is not related directly to this PR.

@spytheman

Copy link
Copy Markdown
Contributor

@JalonSolov without the gc, gc_heap_usage() returns GCHeapUsage{} which has all its fields set to 0.

Comment thread vlib/veb/tests/memory_leak_test.v
@spytheman
spytheman merged commit 8881143 into vlang:master Jan 2, 2026
72 checks passed
@fleximus
fleximus deleted the fix_25423 branch January 2, 2026 19:19
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.

veb memory leak

4 participants