mist
mist copied to clipboard
Close connections automaticaly?
SO the first thing I tried was to use ab
to test a simple ping server from an example.
Turns out each request was always taking 10 seconds to complete. I dug into the code and found out the reason. Without explicitly doing |> response.set_header("connection", "close")
on each request, the connection will be closed on a timeout of 10 seconds.
Is there a reason for this ? It definitely threw me off for a while since it is not mentioned anywhere.
Relevant code: https://github.com/rawhat/mist/blob/master/src/mist/internal/http/handler.gleam
fn close_or_set_timer(
resp: response.Response(ResponseData),
conn: Connection,
sender: Subject(handler.Message(user_message)),
) -> Result(State, process.ExitReason) {
// If the handler explicitly says to close the connection, we should
// probably listen to them
case response.get_header(resp, "connection") {
Ok("close") -> {
let _ = transport.close(conn.transport, conn.socket)
Error(process.Normal)
}
_ -> {
// TODO: this should be a configuration
let timer = process.send_after(sender, 10_000, Internal(Close))
Ok(State(idle_timer: Some(timer)))
}
}
}
The "issue" here is that ApacheBench is sending an HTTP/1.0
request. It seems like that doesn't support keep-alive
. I'll need to handle this particular case (and likely others with HTTP 1.0).
It's definitely not how it should be behaving, but I doubt many things are issuing requests with that version at this point. I'll definitely fix it, but it shouldn't be a problem with basically any other thing.
Thanks for the issue!
I'm going to tentatively say this is fixed. I can properly run ab
and get some results. I'm really only handling explicitly closing the connection with HTTP/1.0
so there may be some other stuff I'm doing incorrectly. But unless it comes up, I'm going to just ignore it 😅