Skip to content

hyper-util: legacy client pool IdleTask spins every pool_idle_timeout when pool is empty #4100

@lrowe

Description

@lrowe

Version

hyper-util 0.1.17, hyper 1.6.0

Platform

Linux 6.19.10 x86_64

Summary

I noticed that Deno's event loop continued spinning every pool idle timeout even after all connections were closed (see: denoland/deno#29444). I've tracked this down to hyper-util and have a proof of concept fix to cancel the IdleTask when the pool is empty here: hyperium/hyper-util#292.

(Sorry, I did not find the contribution guidelines until after filing the draft PR.)

Code Sample

$ DENO_LOG=hyper_util::client=trace deno run --allow-net 'data:,const client = Deno.createHttpClient({ poolIdleTimeout: 100 }); const res = await fetch("http:127.0.0.1:8000/", { client }); await res.bytes(); await new Promise(resolve=>setTimeout(resolve, 2000));'
TRACE RS - hyper_util::client::legacy::pool:679 - checkout waiting for idle connection: ("http", 127.0.0.1:8000)
TRACE RS - hyper_util::client::legacy::connect::http:482 - Http::connect; scheme=Some("http"), host=Some("127.0.0.1"), port=Some(Port(8000))
DEBUG RS - hyper_util::client::legacy::connect::http:768 - connecting to 127.0.0.1:8000
DEBUG RS - hyper_util::client::legacy::connect::http:771 - connected to 127.0.0.1:8000
TRACE RS - hyper_util::client::legacy::client:575 - http1 handshake complete, spawning background dispatcher task
TRACE RS - hyper_util::client::legacy::client:600 - waiting for connection to be ready
TRACE RS - hyper_util::client::legacy::client:610 - connection is ready
TRACE RS - hyper_util::client::legacy::pool:721 - checkout dropped for ("http", 127.0.0.1:8000)
TRACE RS - hyper_util::client::legacy::pool:348 - put; add idle connection for ("http", 127.0.0.1:8000)
DEBUG RS - hyper_util::client::legacy::pool:395 - pooling idle connection for ("http", 127.0.0.1:8000)
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:492 - idle interval evicting expired for ("http", 127.0.0.1:8000)
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:799 - idle interval checking for expired
TRACE RS - hyper_util::client::legacy::pool:810 - pool closed, canceling idle interval

Expected Behavior

When the client connection pool is empty the IdleTask should not wake the event loop.

Actual Behavior

IdleTask wakes the every pool_idle_timeout ms even when empty.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug. Something is wrong. This is bad!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions