hyperium / h2

HTTP 2.0 client & server implementation for Rust.
MIT License
1.34k stars 265 forks source link

High CPU Usage (100%) in Specific Scenarios #781

Closed niceskylei closed 1 month ago

niceskylei commented 1 month ago

Description:

I'm experiencing an issue with the h2 crate where the CPU usage reaches 100% under specific conditions. This issue is consistently reproducible and significantly affects the performance of my application.

Steps to Reproduce:

Expected Behavior:

The CPU usage should remain within normal operating limits and not spike to 100% when the remote client disconnects.

Actual Behavior:

When the remote client disconnects, the CPU usage spikes to 100% and remains there, causing severe performance degradation.

Environment:

Additional Context:

use instruments analyse cpu usage image

Log Files/Output:

using trace log level, repeatedly print below log: queued_data_frame=false

How fix it:

image image I have applied a preliminary fix which seems to mitigate the issue, as the high CPU usage has not reoccurred during my initial tests. However, this fix has not been fully validated, and I am unsure if there are any other side effects or impacts.

seanmonstar commented 1 month ago

Hm, good point, it seems that if a call to write() returns 0, that implies the socket has been closed. A similar looking patch in a pull request would be welcome. The part to discuss is how to signal to the user that not all bytes were written. Perhaps returning a WriteZero io error?