trillium-rs / trillium

Trillium is a composable toolkit for building internet applications with async rust

Home Page:https://trillium.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returning a long Vec<u8> panics

vijfhoek opened this issue · comments

I'm trying to return a 27477 byte long Vec<u8> using conn.ok(...) but when doing so, the tokio/async-std (tried both) runtime workers panic with in the latter case the following backtrace:

Click to expand

[src/main.rs:67] thumbnail.len() = 27477
thread 'async-std/runtime' panicked at 'source slice length (0) does not match destination slice length (8192)', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/mod.rs:3058:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::slice::<impl [T]>::copy_from_slice::len_mismatch_fail
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/mod.rs:3051:13
   3: core::slice::<impl [T]>::copy_from_slice
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/mod.rs:3058:13
   4: <trillium_http::body::Body as futures_io::if_std::AsyncRead>::poll_read
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-http-0.2.0/src/body.rs:129:17
   5: <futures_lite::io::BufReader<R> as futures_io::if_std::AsyncBufRead>::poll_fill_buf
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/io.rs:635:32
   6: <futures_lite::io::copy::{{closure}}::CopyFuture<R,W> as core::future::future::Future>::poll
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/io.rs:87:37
   7: futures_lite::io::copy::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/io.rs:108:5
   8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
   9: trillium_http::conn::Conn<Transport>::send::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-http-0.2.0/src/conn.rs:157:17
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  11: trillium_http::conn::Conn<Transport>::map::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-http-0.2.0/src/conn.rs:144:26
  12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  13: <trillium_server_common::config::Config<ServerType,AcceptorType> as trillium_server_common::config_ext::ConfigExt<ServerType,AcceptorType>>::handle_stream::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/trillium-server-common-0.3.0/src/config_ext.rs:173:22
  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  15: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/future.rs:119:9
  16: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.10.0/src/task/builder.rs:199:17
  17: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.10.0/src/task/task_locals_wrapper.rs:60:13
  18: std::thread::local::LocalKey<T>::try_with
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/thread/local.rs:400:16
  19: std::thread::local::LocalKey<T>::with
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/thread/local.rs:376:9
  20: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.10.0/src/task/task_locals_wrapper.rs:55:9
  21: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.10.0/src/task/builder.rs:197:13
  22: async_executor::Executor::spawn::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.1/src/lib.rs:144:13
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  24: async_task::raw::RawTask<F,T,S>::run
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.0.3/src/raw.rs:489:20
  25: async_task::runnable::Runnable::run
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.0.3/src/runnable.rs:309:18
  26: async_executor::Executor::run::{{closure}}::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.1/src/lib.rs:235:21
  27: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  28: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:529:33
  29: async_executor::Executor::run::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.1/src/lib.rs:242:9
  30: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/future/mod.rs:80:19
  31: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:529:33
  32: async_io::driver::block_on
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-io-1.6.0/src/driver.rs:142:33
  33: async_global_executor::reactor::block_on::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/reactor.rs:3:18
  34: async_global_executor::reactor::block_on
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/reactor.rs:12:5
  35: async_global_executor::threading::thread_main_loop::{{closure}}::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/threading.rs:95:17
  36: std::thread::local::LocalKey<T>::try_with
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/thread/local.rs:400:16
  37: std::thread::local::LocalKey<T>::with
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/thread/local.rs:376:9
  38: async_global_executor::threading::thread_main_loop::{{closure}}
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/threading.rs:89:13
  39: std::panicking::try::do_call
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:401:40
  40: __rust_try
  41: std::panicking::try
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:365:19
  42: std::panic::catch_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panic.rs:434:14
  43: async_global_executor::threading::thread_main_loop
             at /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/threading.rs:88:12
  44: core::ops::function::FnOnce::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

When truncating the Vec to 8192 bytes, the panic disappears.