What is the recommended way to find an unused port to start a server (e.g. Kemal)?

To put it otherwise, is there another way to start a server on a available port than trying to connect it on a given port, increment the port number and so on by trial and error?

I think that’s what happens when you connect to port zero.

Yes. That’s exactly what HTTP::Server.bind_unused_port does.