fasthttp: multi threading fix reads in the socket in linux#26478
Conversation
|
@esquerbatua try |
|
also |
|
Sorry I formatted the veb folder instead fasthttp, it's formatted now |
|
I recommend not changing the logic behind closing the client connection for now. |
|
If I do not close the connection the client keeps waiting until timeout, tested. |
This is the default expected behavior for http1.1 |
|
@claude How connection should bahave in which http version? Show me the rfc reference. |
|
• HTTP/0.9 (very old, single-request): one TCP connection, one request, server returns raw response then closes. (No formal modern RFC; historical notes only.) • No persistent connections, no headers, no request/response framing. • HTTP/1.0 (RFC 1945): by default the server closes the TCP connection after the response; clients and servers may use the Connection: keep-alive extension to request persistence, but it is optional and not reliably supported by all implementations. • RFC: RFC 1945 (HTTP/1.0). • HTTP/1.1 (message framing, persistent by default): connections are persistent by default (multiple requests/responses can be sent sequentially on the same TCP connection). Pipelining (sending multiple requests without waiting for responses) is defined but problematic in practice; implementations more commonly use sequential requests or upgrade to multiplexing (HTTP/2). The Connection header and hop-by-hop semantics are defined here. • Key RFCs: • RFC 7230 (HTTP/1.1 message syntax and routing) — see section on connection management and persistent connections (RFC 7230 §6). • HTTP/2 (binary framing, multiplexed streams over one TCP connection): a single TCP connection carries many independent, interleaved request/response streams concurrently (no head-of-line blocking at the HTTP message level, though TCP-level HOL remains). Uses HPACK for header compression and has explicit stream and connection lifecycle rules. • Key RFCs: • RFC 7540 (Hypertext Transfer Protocol Version 2) — see multiplexing, streams, connection flow control. • HTTP/3 (HTTP semantics over QUIC): moves from TCP to QUIC (UDP-based transport), giving multiplexing without TCP head-of-line blocking and integrated stream- and connection-level flow/congestion control; uses QPACK for header compression with HTTP/3-specific considerations. • Key RFCs: • RFC 9114 (HTTP/3) Pointers / exact references to read • HTTP/1.0: RFC 1945 — https://datatracker.ietf.org/doc/html/rfc1945 |
|
The point it's like if I use vweb or veb without flags, the service works as expected, if I use fast http, the connection keeps open |
|
Can there be a separate thread, that loops over all current opened connections, every say 10 seconds, and closes them, if there were no activity on them for say 1 minute? |
|
@esquerbatua Can you share the code which you're facing issues? |
The simplest veb server should give timeout in all of the request. I didn't have time to test it changing the handing of the connection close. module main
import veb { Result }
pub struct Context {
veb.Context
}
struct App {
}
fn main() {
mut app := App{}
veb.run_at[App, Context](
mut app,
host: '0.0.0.0',
port: 8080,
family: .ip,
) or { panic(err) }
}
@['/']
pub fn (app &App) index(mut ctx Context) Result {
return ctx.ok('')
} |
Sorry if I'm wrong: If we do that, always we are going to give extra time to all of the request, making veb or fasthttp so slow, make them useless with big load time and extra handle of the connection. |
|
Why not just close the connection at client side, as usual or handle |
I'm sorry, but I'm still struggling to understand how the connection remaining active after sending the reply could be a problem |
The client doesn't have to wait for the connection timeout; it simply receives all the responses, check |
|
I reverted the changes in the clousure as they are, shouldn't modify the old behaviour @enghitalo |
|
Thanks |
yes |
| // Read all available data from the socket | ||
| mut total_bytes_read := 0 | ||
| mut all_data := []u8{cap: server.max_request_buffer_size} | ||
| mut readed_request_buffer := []u8{len: server.max_request_buffer_size, cap: server.max_request_buffer_size} |
There was a problem hiding this comment.
[]u8{len: server.max_request_buffer_size}
There was a problem hiding this comment.
this it's not changed
spytheman
left a comment
There was a problem hiding this comment.
Thank you @esquerbatua 🙇🏻 .
Thank you @enghitalo .
fasthttp:
veb: