-
Notifications
You must be signed in to change notification settings - Fork 246
Description
Goal or context for the feature
Previously, due to the large amount of data, some queries were already experiencing excessively long processing times. The most directly affected APIs were get_cells, get_transactions, and get_cells_capacity.
While the two PRs(#4576, #4529) introduced configurable limits for get_transactions and get_cells_capacity, get_cells did not improve this. It does not support request limit restrictions, and its problem lies in the fact that it may need to iterate through a large number of cells with a small return value. This is not entirely consistent with the issues of the other two RPC APIs. Furthermore, users can construct an empty filter to iterate through all cells, resulting in significant resource waste and potentially enabling DoS attacks.
relations:#4469
Describe the solution you'd like
The cost of these interfaces varies depending on the host machine's configuration. We plan to impose some time consumption limits on the interfaces, roughly as shown below:
struct TimeoutIterator<I> {
inner: I,
start_time: Instant,
timeout: Duration,
timed_out: bool,
}
impl<I: Iterator> Iterator for TimeoutIterator<I> {
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
if self.start_time.elapsed() > self.timeout {
self.timed_out = true;
return None;
}
self.inner.next()
}
}During the iteration, time will be controlled. A single query will have a default maximum time interval of 5-10 seconds. If a timeout occurs, the query will be forcibly terminated, and an error will be returned.
Perhaps nginx should also be equipped with corresponding interface query timeout configurations, or provide a similar template with default configurations and timeout configurations for whether RPC interfaces are public or private.