Skip to content

fix(buffer): assert non-zero bound on construction#867

Open
Alpy16 wants to merge 2 commits into
tower-rs:masterfrom
Alpy16:fix-buffer-zero-bound
Open

fix(buffer): assert non-zero bound on construction#867
Alpy16 wants to merge 2 commits into
tower-rs:masterfrom
Alpy16:fix-buffer-zero-bound

Conversation

@Alpy16
Copy link
Copy Markdown

@Alpy16 Alpy16 commented May 21, 2026

Closes #861

Description
Initializing Buffer or BufferLayer with a capacity bound of 0 creates an invalid configuration state. This bypasses initial validation and causes an unrecoverable runtime panic down the line when the underlying mpsc::channel allocation is executed.

This patch adds a defensive assert!(bound > 0, ...) boundary guard to both the BufferLayer::new and Buffer::pair constructors. This shifts a latent runtime crash into a predictable, fail-fast initialization panic.

Type of Change
Bug fix (non-breaking change enforcing defensive API boundaries)

Verification
Added #[should_panic] integration tests to tower/tests/buffer/main.rs to verify that both direct instantiation and layer application fail safely when configured with a bound of 0.

Verified workspace tests pass via cargo test --test buffer --all-features.

@seanmonstar
Copy link
Copy Markdown
Collaborator

Probably the docs on the constructor should also mention that the value must be greater than 0, maybe in a # Panics section?

@Alpy16
Copy link
Copy Markdown
Author

Alpy16 commented May 21, 2026

I'll add the # Panics section to the documentation for both constructors right now and get those pushed up. Thanks for the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

buffer: bound = 0 panics in Buffer::new / Buffer::pair (and via BufferLayer::new)

2 participants