Hello,
Summary
I would like to propose an improvement to enhance the stability of Pingora's upstream peer and health check modules by removing potential runtime panics during initialization.
The Problem
Several constructors in the codebase rely on .unwrap(), which can cause a worker process to panic unexpectedly at runtime if an error occurs:
-
HttpPeer:
HttpPeer::new() and HttpPeer::new_mtls() call .unwrap() on the result of to_socket_addrs() and on the subsequent iterator (.next()). If DNS resolution fails or returns no addresses, the process panics.
-
HttpHealthCheck:
HttpHealthCheck::new() and HttpHealthCheck::new_custom() use .unwrap() during request header construction (RequestHeader::build) and peer template initialization.
Proposed Solution
- Refactor these initializers to safely propagate errors using the
? operator instead of panicking.
- Change the return signature of
HttpPeer::new, HttpPeer::new_mtls, HttpHealthCheck::new, and HttpHealthCheck::new_custom to return Result<Self> instead of Self.
- Update the associated test suites to handle the new
Result returns properly.
I have prepared a Pull Request containing these modifications and updated the relevant tests to ensure the codebase remains stable and compiles cleanly.
Pingora info
Pingora version: 0.8.1
Steps to reproduce
A panic occurs if the DNS server is unreachable.
Hello,
Summary
I would like to propose an improvement to enhance the stability of Pingora's upstream peer and health check modules by removing potential runtime panics during initialization.
The Problem
Several constructors in the codebase rely on
.unwrap(), which can cause a worker process to panic unexpectedly at runtime if an error occurs:HttpPeer:HttpPeer::new()andHttpPeer::new_mtls()call.unwrap()on the result ofto_socket_addrs()and on the subsequent iterator (.next()). If DNS resolution fails or returns no addresses, the process panics.HttpHealthCheck:HttpHealthCheck::new()andHttpHealthCheck::new_custom()use.unwrap()during request header construction (RequestHeader::build) and peer template initialization.Proposed Solution
?operator instead of panicking.HttpPeer::new,HttpPeer::new_mtls,HttpHealthCheck::new, andHttpHealthCheck::new_customto returnResult<Self>instead ofSelf.Resultreturns properly.I have prepared a Pull Request containing these modifications and updated the relevant tests to ensure the codebase remains stable and compiles cleanly.
Pingora info
Pingora version: 0.8.1
Steps to reproduce
A panic occurs if the DNS server is unreachable.