hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.58k stars 1.6k forks source link

Hyper uses featured functions from `socket2` without explicitly requiring it #3045

Closed papey closed 2 years ago

papey commented 2 years ago

Version

As a transitive dependency from another crate, I get hyper = "0.14.22", and then socket2 = "0.4.7".

Platform

Linux elrond 6.0.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 03 Nov 2022 18:01:58 +0000 x86_64 GNU/Linux

Description

When a project adds hyper as a transitive dependency, some required features for socket2 are missing, and my project wont compile.

I tried this code:

some_create = "X.Y.Z # adds transitive deps on hyper"

Cargo.lock :

[[package]]
name = "hyper"
version = "0.14.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064"
dependencies = [
 "bytes",
 "futures-channel",
 "futures-core",
 "futures-util",
 "h2",
 "http",
 "http-body",
 "httparse",
 "httpdate",
 "itoa 1.0.4",
 "pin-project-lite",
 "socket2", <-----
 "tokio",
 "tower-service",
 "tracing",
 "want",
]

I expected to see this happen: cargo build without issue

Instead, this happened:

  --> /home/papey/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.22/src/server/tcp.rs:59:12
   |
59 |         ka.with_interval(interval)
   |            ^^^^^^^^^^^^^ method not found in `TcpKeepalive`

It leads to those lines or this doc in socket2.

With the mention of :

Available on crate feature all and (Android or DragonFly BSD or FreeBSD or Fuchsia or illumos or Linux or NetBSD or Apple or Windows) only.

On the function used in hyper tcp.rs.

Adding socket2 as a dep with the the all feature in my Cargo.toml file solve the issue :

socket2 = { version = "0.4.7", features = ["all"] }

but it's far from ideal and I think that it should be enabled on hyper side. I can work on the PR if you want.

Thanks :+1:

LucioFranco commented 2 years ago

Should be fixed via https://github.com/hyperium/hyper/pull/3047

papey commented 2 years ago

Fix confirmed ! Kudos @LucioFranco && @seanmonstar :+1: