From 171df75cc7778532937639d96a4d23a82c3a4cc4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 19 May 2025 15:30:21 +0300 Subject: [PATCH] veb: reduce veb_max_write_bytes from 16KB to 2KB (fix sending large dynamic responses from veb on macos/freebsd) (fix #24523) (#24522) --- vlib/net/tcp.c.v | 3 +++ vlib/veb/consts.v | 2 +- vlib/veb/tests/veb_test.v | 7 +++++++ vlib/veb/tests/veb_test_server.v | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/vlib/net/tcp.c.v b/vlib/net/tcp.c.v index b518f7c13e..10dd28c54d 100644 --- a/vlib/net/tcp.c.v +++ b/vlib/net/tcp.c.v @@ -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 diff --git a/vlib/veb/consts.v b/vlib/veb/consts.v index e8be862870..7832e73692 100644 --- a/vlib/veb/consts.v +++ b/vlib/veb/consts.v @@ -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)) diff --git a/vlib/veb/tests/veb_test.v b/vlib/veb/tests/veb_test.v index faa480cebd..d52038af00 100644 --- a/vlib/veb/tests/veb_test.v +++ b/vlib/veb/tests/veb_test.v @@ -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 +} diff --git a/vlib/veb/tests/veb_test_server.v b/vlib/veb/tests/veb_test_server.v index 022d89a341..02ec2ae1d2 100644 --- a/vlib/veb/tests/veb_test_server.v +++ b/vlib/veb/tests/veb_test_server.v @@ -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) +}