veb: reduce veb_max_write_bytes from 16KB to 2KB (fix sending large dynamic responses from veb on macos/freebsd) (fix #24523) (#24522)

This commit is contained in:
Delyan Angelov 2025-05-19 15:30:21 +03:00 committed by GitHub
parent b1fefc5e0c
commit 171df75cc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 1 deletions

View File

@ -239,6 +239,9 @@ pub fn (mut c TcpConn) write_ptr(b &u8, len int) !int {
}
if sent < 0 {
code := error_code()
$if trace_tcp_send_failures ? {
eprintln('>>> TcpConn.write_ptr | send_failure, data.len: ${len:6}, total_sent: ${total_sent:6}, remaining: ${remaining:6}, ptr: ${voidptr(ptr):x}, c.write_timeout: ${c.write_timeout:3} => sent: ${sent:6}, error code: ${code:3}')
}
if code in [int(error_ewouldblock), int(error_eagain), C.EINTR] {
c.wait_for_write()!
continue

View File

@ -4,7 +4,7 @@ import net.http
// max read and write limits in bytes
const max_read = int($d('veb_max_read_bytes', 8192))
const max_write = int($d('veb_max_write_bytes', 16384))
const max_write = int($d('veb_max_write_bytes', 2048))
pub const max_http_post_size = $d('veb_max_http_post_size_bytes', 1048576)
pub const default_port = int($d('veb_default_port', 8080))

View File

@ -376,3 +376,10 @@ fn test_empty_querypath() {
x = http.get('http://${localserver}///') or { panic(err) }
assert x.body == 'Welcome to veb'
}
fn test_large_response() {
received := simple_tcp_client(path: '/large_response') or { panic(err) }
assert_common_headers(received)
assert received.ends_with('}]')
assert received.len == 830778
}

View File

@ -152,3 +152,22 @@ fn (mut app ServerApp) exit_gracefully() {
time.sleep(100 * time.millisecond)
exit(0)
}
pub fn (mut app ServerApp) large_response(mut ctx ServerContext) veb.Result {
struct Tick {
date_time string
timestamp i64
value f64
}
mut arr := []Tick{}
for i in 0 .. 16000 {
arr << Tick{
date_time: i.str()
timestamp: i
value: i
}
}
return ctx.json(arr)
}