cloudflare / cloudflare/pingora

Start server on arbitrary free port or uds address

Open
#374 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
27.4k
Forks
1.7k
Avg merge
6h 22m
Merged PRs (30d)
3

Description

## What is the problem your feature solves, or the need it fulfills?

I'd like the capability to launch a Pingora server on a random available [port](https://doc.rust-lang.org/std/net/struct.TcpListener.html#method.bind) or [UDS address](https://docs.rs/uds/latest/uds/struct.UnixSocketAddr.html#method.new_unspecified) and get back the port or address chosen.

## Describe the solution you'd like

We can take inspiration from Tonic's implementation, which allows us to provide the listener after binding.

```rust
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();

println!(listener.local_addr().unwrap().port()); // prints some random port assigned by the OS

tonic::transport::Server::builder()
.add_service(svc)
.serve_with_incoming(tokio_stream::wrappers::TcpListenerStream::new(listener))
.await
.unwrap();
```

## Describe alternatives you've considered

...

## Additional context

I need to launch multiple Pingora servers simultaneously for integration testing, each on a unique, dynamically assigned port or UDS address, to prevent port/address collisions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.