pingora icon indicating copy to clipboard operation
pingora copied to clipboard

The example server fails to build

Open yonas opened this issue 1 year ago • 3 comments

Describe the bug

The example server fails to build:

use async_trait::async_trait;
use pingora::prelude::*;
use std::sync::Arc;

fn main() {
    let mut my_server = Server::new(None).unwrap();
    my_server.bootstrap();
    my_server.run_forever();
}

Pingora info

Please include the following information about your environment:

Pingora version: 8797329 Rust version: rustc 1.76.0-nightly (37b2813a7 2023-11-24) (built from a source tarball) Operating system version: FreeBSD 14

Expected results

What were you expecting to happen?

Observed results

❯ cargo build --release
   Compiling pingora-cache v0.1.0
    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0308]: mismatched types
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:111:9
    |
111 |         self.connector.get_stream(&peer).await.map(|_| {})
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `pingora_error::Error`, found `pingora_core::Error`
    |
    = note: `pingora_core::Error` and `pingora_error::Error` have similar names, but are actually distinct types
note: `pingora_core::Error` is defined in crate `pingora_error`
   --> /home/yonas/git/pingora/pingora-error/src/lib.rs:33:1
    |
33  | pub struct Error {
    | ^^^^^^^^^^^^^^^^
note: `pingora_error::Error` is defined in crate `pingora_error`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-error-0.1.0/src/lib.rs:33:1
    |
33  | pub struct Error {
    | ^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `pingora_error` are being used?
note: return type inferred to be `Result<(), Box<pingora_error::Error>>` here
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:108:59
    |
108 |       async fn check(&self, target: &Backend) -> Result<()> {
    |  ___________________________________________________________^
109 | |         let mut peer = self.peer_template.clone();
110 | |         peer._address = target.addr.clone();
111 | |         self.connector.get_stream(&peer).await.map(|_| {})
112 | |     }
    | |_____^

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0277]: `?` couldn't convert the error to `Box<pingora_error::Error>`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:202:67
    |
202 |         let session = self.connector.get_http_session(&peer).await?;
    |                                                                   ^ the trait `From<Box<pingora_core::Error>>` is not implemented for `Box<pingora_error::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <Box<indexmap::map::slice::Slice<K, V>> as From<&indexmap::map::slice::Slice<K, V>>>
              <Box<indexmap::set::slice::Slice<T>> as From<&indexmap::set::slice::Slice<T>>>
              <Box<OsStr> as From<Cow<'_, OsStr>>>
              <Box<OsStr> as From<OsString>>
              <Box<OsStr> as From<&OsStr>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<http::response::Parts> as From<Box<ResponseHeader>>>
              <Box<Path> as From<Cow<'_, Path>>>
            and 23 others
    = note: required for `Result<(), Box<pingora_error::Error>>` to implement `FromResidual<Result<Infallible, Box<pingora_core::Error>>>`

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0308]: mismatched types
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:206:38
    |
206 |         session.write_request_header(req).await?;
    |                 -------------------- ^^^ expected `pingora_http::RequestHeader`, found `RequestHeader`
    |                 |
    |                 arguments to this method are incorrect
    |
    = note: `RequestHeader` and `pingora_http::RequestHeader` have similar names, but are actually distinct types
note: `RequestHeader` is defined in crate `pingora_http`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-http-0.1.0/src/lib.rs:68:1
    |
68  | pub struct RequestHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^
note: `pingora_http::RequestHeader` is defined in crate `pingora_http`
   --> /home/yonas/git/pingora/pingora-http/src/lib.rs:68:1
    |
68  | pub struct RequestHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `pingora_http` are being used?
note: method defined here
   --> /home/yonas/git/pingora/pingora-core/src/protocols/http/client.rs:47:18
    |
47  |     pub async fn write_request_header(&mut self, req: Box<RequestHeader>) -> Result<()> {
    |                  ^^^^^^^^^^^^^^^^^^^^

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0277]: `?` couldn't convert the error to `Box<pingora_error::Error>`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:206:48
    |
206 |         session.write_request_header(req).await?;
    |                                                ^ the trait `From<Box<pingora_core::Error>>` is not implemented for `Box<pingora_error::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <Box<indexmap::map::slice::Slice<K, V>> as From<&indexmap::map::slice::Slice<K, V>>>
              <Box<indexmap::set::slice::Slice<T>> as From<&indexmap::set::slice::Slice<T>>>
              <Box<OsStr> as From<Cow<'_, OsStr>>>
              <Box<OsStr> as From<OsString>>
              <Box<OsStr> as From<&OsStr>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<http::response::Parts> as From<Box<ResponseHeader>>>
              <Box<Path> as From<Cow<'_, Path>>>
            and 23 others
    = note: required for `Result<(), Box<pingora_error::Error>>` to implement `FromResidual<Result<Infallible, Box<pingora_core::Error>>>`

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0277]: `?` couldn't convert the error to `Box<pingora_error::Error>`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:212:45
    |
212 |         session.read_response_header().await?;
    |                                             ^ the trait `From<Box<pingora_core::Error>>` is not implemented for `Box<pingora_error::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <Box<indexmap::map::slice::Slice<K, V>> as From<&indexmap::map::slice::Slice<K, V>>>
              <Box<indexmap::set::slice::Slice<T>> as From<&indexmap::set::slice::Slice<T>>>
              <Box<OsStr> as From<Cow<'_, OsStr>>>
              <Box<OsStr> as From<OsString>>
              <Box<OsStr> as From<&OsStr>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<http::response::Parts> as From<Box<ResponseHeader>>>
              <Box<Path> as From<Cow<'_, Path>>>
            and 23 others
    = note: required for `Result<(), Box<pingora_error::Error>>` to implement `FromResidual<Result<Infallible, Box<pingora_core::Error>>>`

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0308]: mismatched types
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:217:23
    |
217 |             validator(resp)?;
    |             --------- ^^^^ expected `ResponseHeader`, found `pingora_http::ResponseHeader`
    |             |
    |             arguments to this function are incorrect
    |
    = note: `pingora_http::ResponseHeader` and `ResponseHeader` have similar names, but are actually distinct types
note: `pingora_http::ResponseHeader` is defined in crate `pingora_http`
   --> /home/yonas/git/pingora/pingora-http/src/lib.rs:288:1
    |
288 | pub struct ResponseHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: `ResponseHeader` is defined in crate `pingora_http`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-http-0.1.0/src/lib.rs:288:1
    |
288 | pub struct ResponseHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `pingora_http` are being used?
note: implementation defined here
   --> /wrkdirs/usr/ports/lang/rust-nightly/work/rustc-nightly-src/library/alloc/src/boxed.rs:2019:1

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror[E0277]: `?` couldn't convert the error to `Box<pingora_error::Error>`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-load-balancing-0.1.0/src/health_check.rs:225:49
    |
225 |         while session.read_response_body().await?.is_some() {
    |                                                 ^ the trait `From<Box<pingora_core::Error>>` is not implemented for `Box<pingora_error::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <Box<indexmap::map::slice::Slice<K, V>> as From<&indexmap::map::slice::Slice<K, V>>>
              <Box<indexmap::set::slice::Slice<T>> as From<&indexmap::set::slice::Slice<T>>>
              <Box<OsStr> as From<Cow<'_, OsStr>>>
              <Box<OsStr> as From<OsString>>
              <Box<OsStr> as From<&OsStr>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<http::response::Parts> as From<Box<ResponseHeader>>>
              <Box<Path> as From<Cow<'_, Path>>>
            and 23 others
    = note: required for `Result<(), Box<pingora_error::Error>>` to implement `FromResidual<Result<Infallible, Box<pingora_core::Error>>>`

    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[KSome errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
    Building [=======================> ] 300/305: pingora-cache, pingora-load-balancing                                                                                                                            
[Kerror: could not compile `pingora-load-balancing` (lib) due to 7 previous errors
warning: build failed, waiting for other jobs to finish...
    Building [=======================> ] 301/305: pingora-cache                                                                                                                                                    
[Kerror[E0308]: mismatched types
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-cache-0.1.0/src/put.rs:133:82
    |
133 |                 HttpTask::Header(header, _eos) => match self.cache_put.cacheable(&header) {
    |                                                                        --------- ^^^^^^^ expected `&ResponseHeader`, found `&Box<ResponseHeader>`
    |                                                                        |
    |                                                                        arguments to this method are incorrect
    |
    = note: expected reference `&pingora_http::ResponseHeader`
               found reference `&Box<pingora_http::ResponseHeader>`
note: method defined here
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-cache-0.1.0/src/put.rs:27:8
    |
27  |     fn cacheable(&self, response: &ResponseHeader) -> RespCacheable {
    |        ^^^^^^^^^        -------------------------

    Building [=======================> ] 301/305: pingora-cache                                                                                                                                                    
[Kerror[E0277]: `?` couldn't convert the error to `Box<pingora_error::Error>`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-cache-0.1.0/src/put.rs:176:65
    |
176 |         while let Some(data) = session.read_request_body().await? {
    |                                                                 ^ the trait `From<Box<pingora_core::Error>>` is not implemented for `Box<pingora_error::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <Box<indexmap::map::slice::Slice<K, V>> as From<&indexmap::map::slice::Slice<K, V>>>
              <Box<indexmap::set::slice::Slice<T>> as From<&indexmap::set::slice::Slice<T>>>
              <Box<OsStr> as From<Cow<'_, OsStr>>>
              <Box<OsStr> as From<OsString>>
              <Box<OsStr> as From<&OsStr>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<http::response::Parts> as From<Box<pingora_http::ResponseHeader>>>
              <Box<Path> as From<Cow<'_, Path>>>
            and 23 others
    = note: required for `std::result::Result<std::option::Option<NoCacheReason>, Box<pingora_error::Error>>` to implement `FromResidual<std::result::Result<Infallible, Box<pingora_core::Error>>>`

    Building [=======================> ] 301/305: pingora-cache                                                                                                                                                    
[Kerror[E0308]: mismatched types
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-cache-0.1.0/src/put.rs:336:58
    |
336 |                     tasks.push(HttpTask::Header(Box::new(header), self.state.is_done()));
    |                                                 -------- ^^^^^^ expected `pingora_http::ResponseHeader`, found a different `pingora_http::ResponseHeader`
    |                                                 |
    |                                                 arguments to this function are incorrect
    |
    = note: `pingora_http::ResponseHeader` and `pingora_http::ResponseHeader` have similar names, but are actually distinct types
note: `pingora_http::ResponseHeader` is defined in crate `pingora_http`
   --> /home/yonas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pingora-http-0.1.0/src/lib.rs:288:1
    |
288 | pub struct ResponseHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: `pingora_http::ResponseHeader` is defined in crate `pingora_http`
   --> /home/yonas/git/pingora/pingora-http/src/lib.rs:288:1
    |
288 | pub struct ResponseHeader {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `pingora_http` are being used?
note: associated function defined here
   --> /wrkdirs/usr/ports/lang/rust-nightly/work/rustc-nightly-src/library/alloc/src/boxed.rs:215:12

    Building [=======================> ] 301/305: pingora-cache                                                                                                                                                    
[Kerror: could not compile `pingora-cache` (lib) due to 3 previous errors

yonas avatar Feb 28 '24 17:02 yonas

Thanks for testing and reporting this! I'll look into it today 😊

johnhurt avatar Feb 28 '24 17:02 johnhurt

We can't seem to replicate this. Mind posting your cargo.lock file?

johnhurt avatar Feb 29 '24 00:02 johnhurt

@johnhurt I'm not able to replicate this either for some reason. The do-nothing server and the load balancing proxy both work now.

I've submitted a patch to fix an earlier bug. #28

yonas avatar Feb 29 '24 06:02 yonas

Awesome, that looks legit to me. It's assigned, so it should get attention soon. I'm going to close this issue and let the pr stand on its own.

johnhurt avatar Mar 02 '24 12:03 johnhurt