[SIGNIFICANT] remove_service uses recursive async -- stack depth risk #28

Open
opened 2026-05-11 10:52:02 +00:00 by thabeta · 1 comment
Owner

Problem

remove_service in api.rs recursively calls itself with Box::pin(self.remove_service(dep_name)).await for each dependent. In a deep dependency chain (A<-B<-C<-D<-...<-Z), this creates deep async recursion.

While Box::pin prevents stack overflow on the Rust call stack, each level still allocates a Box and a future. A chain of 100+ services could cause issues.

Impact

Memory allocation per recursion level. In extreme cases, could hit allocation limits or cause latency spikes.

Files

  • crates/my_init_server/src/supervisor/api.rs -- remove_service recursive call

Suggested Fix

  • Convert to iterative approach using a queue/stack
  • Collect all dependents first (BFS/DFS), then stop them in order iteratively
## Problem `remove_service` in `api.rs` recursively calls itself with `Box::pin(self.remove_service(dep_name)).await` for each dependent. In a deep dependency chain (A<-B<-C<-D<-...<-Z), this creates deep async recursion. While `Box::pin` prevents stack overflow on the Rust call stack, each level still allocates a Box and a future. A chain of 100+ services could cause issues. ## Impact Memory allocation per recursion level. In extreme cases, could hit allocation limits or cause latency spikes. ## Files - `crates/my_init_server/src/supervisor/api.rs` -- `remove_service` recursive call ## Suggested Fix - Convert to iterative approach using a queue/stack - Collect all dependents first (BFS/DFS), then stop them in order iteratively
Member

Classification: valid-bug — remove_service recursively calls Box::pin(self.remove_service()) for each dependent, creating unbounded Box/future allocation per recursion level.

Each recursion level allocates a Box and future; in extreme dependency chains this could cause allocation pressure or latency spikes.

> Classification: valid-bug — remove_service recursively calls Box::pin(self.remove_service()) for each dependent, creating unbounded Box/future allocation per recursion level. Each recursion level allocates a Box and future; in extreme dependency chains this could cause allocation pressure or latency spikes.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_code/my_init#28
No description provided.