Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 03:31
    codecov[bot] commented #1797
  • 03:25
    codecov[bot] commented #1797
  • 02:54
    robjtede edited #1797
  • 02:54
    robjtede edited #1797
  • 02:54
    robjtede synchronize #1797
  • 02:54

    robjtede on quality

    update changelog (compare)

  • 02:52
    robjtede review_requested #1797
  • 02:52
    robjtede labeled #1797
  • 02:52
    robjtede opened #1797
  • 02:52
    robjtede labeled #1797
  • 02:47

    robjtede on quality

    refactor quality and use TryFro… (compare)

  • 02:46

    robjtede on quality


  • 01:11
    robjtede deleted #1796
  • 01:11
    robjtede closed #1796
  • 01:10
    codecov[bot] commented #1793
  • 01:01
    robjtede commented #1796
  • 00:52
    d00z3l opened #1796
  • 00:37
    robjtede synchronize #1793
  • 00:37

    robjtede on accept-precedence

    add method for getting accept t… (compare)

  • 00:31

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ 2… (compare)

Timo Tiuraniemi

Hi! I'm new to actix and trying hard to be able to call a two async methods in a row inside an actor. This might be also about me not understanding rust, so bear with me. I have an actor which is supposed to receive multiple calls which should be pushed to and read from incoming_writer and outgoing_reader respectively:

pub struct MyActor {
    incoming_writer: PipeWriter,
    outgoing_reader: PipeReader,
impl MyActor {
    pub fn new() -> Self {
        let (mut incoming_writer, incoming_reader) = async_pipe::pipe();
        let (outgoing_writer, mut outgoing_reader) = async_pipe::pipe();
        Self {

I am trying to call these according to the examples in found in actix github, like this:

pub struct MyMessage {
    pub payload: Bytes,
impl Message for MyMessage {
    type Result = Result<Bytes, std::io::Error>;
impl Handler<MyMessage> for MyActor {
    type Result = ResponseActFuture<MyActor, Result<Bytes, std::io::Error>>;
    fn handle(&mut self, msg: MyMessage _ctx: &mut Context<Self>) -> Self::Result {
        let mut v = Vec::new();
        let fut = Box::new(self.incoming_writer.write_all(&msg.payload)).and_then(|_| {
                .read_to_end(&mut v)
                .map_ok(|_| Bytes::from(v))

This causes however error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements from the write_all line there. Any ideas how that could be fixed? Is this kind of long-lived Actor internal state variable possible to do?

52 replies
Mahdi Robatipoor
use actix_web::{get, web, App, HttpServer, Responder};
use mongodb::bson::doc;
use mongodb::options;
use mongodb::Client;
use mongodb::Database;

pub async fn insert_name(path: web::Path<String>, data: web::Data<Database>) -> impl Responder {
    let col = data.collection("rcol");
    col.insert_one(doc! {"name":path.into_inner()}, None)
    "insert name to mongodb"

async fn main() {
    let ops = options::ClientOptions::parse("mongodb://")
    let cli = Client::with_options(ops).unwrap();
    let db = cli.database("rdb");
    HttpServer::new(move || App::new().data(db.clone()).service(insert_name))
why this code not compiled ??? The strange thing is that no error is observed
4 replies

I'm running actix-web and the aspotify spotify web api client library. This library implements retries using tokio::timer. Whenever it tries to start a timer tokio throws an error saying:

thread 'actix-rt:worker:1' panicked at 'there is no timer running, must be called from the context of Tokio runtime or `rt` is not enabled'

Annotating my main method with actix_web::main or tokio::main and using run_in_tokio doesn't seem to change anything. Any idea what could be wrong here?

14 replies
Rob Ede
does anyone have a direct comparison of Actix vs like Riker or Bastion or something?
35 replies
Thiago Veronezi

Hi community!

I'm trying to use data with my handler, but the server throws a App data is not configured, to configure use App::data() at me. Can you help me finding what I'm doing wrong here? This is a tiny project that reproduces the issue.


4 replies
Kevin Hoffman
Is there a way to react to a system shutdown? I would like my control plane to emit a "host stopped" event as the system shuts down. With my regular actors I can use the stopped function, but my system services don't have a stopped function. Is there an idiomatic way to run some bit of code as a system's "last gasp" ?
1 reply
Rob Ede

I've started a somewhat-official Discord server, that aims to replace the community-run server because it appears to have been abandoned by the original creator. It will be owned by the core team and a place where you can ask for help and discuss development with me (and eventually the rest of the team).


This gitter will remain a place to ask for help for the forseeable future.
Augusto César Dias
if a web::Path<MyStruct> fails to be deserialised
shouldn't actix return a bad request instead of a not found?
4 replies
Saint Tukio

Hi guys, Do anyone knows why I keep receiving below error intermittently?

ERROR actix_http::response] Internal Server Error: Redis(IO(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" }))

My setup has both RedisSession and RedisActor all will work fine and occasionally I will receive the error above:

let private_key = rand::thread_rng().gen::<[u8; 32]>();

HttpServer::new(move || {
        // redis session middleware
        .wrap(RedisSession::new("", &private_key))

Any suggestion on how to resolve this will be greatly appreciated.

22 replies
Saint Tukio
Is it possible to use actix_web_httpauth::extractors::bearer::BearerAuth with redirect middleware as described in this example?
Filippo Orrù
Hi, how can I define a Message that just returns a bool? It's a simple GetInfo that has Result = bool but when I do address.send(GetInfo).into_actor(self).then(...) it doesn't work.
I would have searched but the gitter search is so shitty, I can't see more than 5 results from 2018
4 replies
Axel C.
Hello, is it possible to call async functions inside an extractor? I have an extractor that needs to call redis asynchronously and i can't .await inside the from_request function...
39 replies
Axel C.
Is there any warning logged when your at risk or have already depleted your provisioned workers? Currently load testing and exploring possible bottlenecks.
2 replies
What's the most straightforward way of writing a function signature that returns an App or HttpServer? I've got a use case where depending on startup it might be driven from a library or a main call and would like a generic function that that can create a new instance and return it for use.
Maximilian Stroh
Hey there, may someone help me out with a beginner question? I just tried to make the unit testing example work https://actix.rs/docs/testing/ with a simple function, but i keep getting call expression requires function errors on let resp = index(req).await
3 replies
Alan Briolat
Is it bad if I really want to do impl Actor for Arc<Mutex<Something>> ?
18 replies
Abdelmonem Mostafa
I am new in actix web and I want to make an API to post data like photo and user name so try to use this example https://github.com/actix/examples/blob/master/multipart/src/main.rs
but I couldn't send username field with the photo so could anyone help me?
Hi, i'm facing a strange issue when upgrading actix-cors to 0.5.0, seems that the request done via browser are skipped, until I switch from Cors::default() to Cors::permissive(), then if I return to Cors::default() the request are correctly processed. Did you have any clue?
21 replies
Hi folks
1 reply
I am trying to build unit tests with actix_rt
Is there a way to sleep?
or maybe I should ask, what is the best way to get the thread to sleep
1 reply
when using acttix_rt
Hi everyone, I am a new in actix and I want to ask about using Nats with actix actor while actix actor already have a method to send and handle message with each others.
Abdelmonem Mostafa
hello everyone ,I want to know when to use actix-web-form crate?
7 replies
Malhar Vora

My middleware takes ServiceResponse from actix_web::service even if it is not even imported. I imported actix_web::dev::*. Here is an error.

error[E0599]: no method named `is_success` found for struct `actix_web::service::ServiceResponse<B>` in the current scope
   --> src/requestid_middleware.rs:110:20
110 |             if res.is_success() || res.is_informational() || res.is_redirection() {
    |                    ^^^^^^^^^^ method not found in `actix_web::service::ServiceResponse<B>`

Here are imports

use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use actix_web::http::{HeaderName, HeaderValue};
use actix_web::{web::Data, Error, HttpMessage};

use futures::future::{ok, Ready};

use crate::state::State;

use uuid::Uuid;

pub struct RequestId;

impl<S, B> Transform<S> for RequestId
    S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
    S::Future: 'static,
    B: 'static,
    type Request = ServiceRequest;
    type Response = ServiceResponse<B>;
    type Error = Error;
    type InitError = ();
    type Transform = RequestIdMiddleware<S>;
    type Future = Ready<Result<Self::Transform, Self::InitError>>;

    fn new_transform(&self, service: S) -> Self::Future {
        ok(RequestIdMiddleware { service })

I have following calls in in `Call` method of my middleware.
fn call(&mut self, req: ServiceRequest) -> Self::Future {
    let fut = self.service.call(req);
        if res.is_success() || res.is_informational() || res.is_redirection() {
        } else {
16 replies
In actix, an actor will stop if all addresses to the actor get dropped and no evented objects are left in the context. In this context, what's an evented object? Is a stream added to the actor's context an evented object?
6 replies
Hi, is there a way to bind a new SSL key/cert pair when the HttpServer is running? I currently use HttpServer::bind_openssl when creating the server, but I need to rotate the key/cert at some point. Is this possible without having to restart the HTTP server? Thanks
Hi, I am a new in actix and I want to write some function like this, but it wrong, i viewed one Similar situation in actix-web source code, it used clone(), is the clone() necessary?
pub fn get_extension_data<T: 'static>(req: &actix_web::HttpRequest) -> Option<&mut T> {
    let mut extensions = req.extensions_mut();
11 |     extensions.get_mut::<T>()
   |     ----------^^^^^^^^^^^^^^^
   |     |
   |     returns a value referencing data owned by the current function
   |     `extensions` is borrowed here
10 replies

Ruben De Smet I have recently written a PR for rust-multipart-rfc7578: ferristseng/rust-multipart-rfc7578#19, but that crate seems kinda dead.

That crate can be used to throw multipart form data inside an awc client. I know there is actix-multipart, but that only includes server-side support for multipart. Would a PR with the client support be welcomed?

4 replies
Michael Hanley
What would be the ideal way to attach some data to a request in a middleware so that I can use it in handlers?
2 replies
Darragh Van Tichelen
The first call of the closure of actor context.run_interval seems to happen after the duration elapsed. is it possible to run immediately and then after every provided duration ? or should I just call the closure manually once before
2 replies
Kunjan Dalal
Hi, any body is using actix actor framework. Any one knows any future plans for same. Documentation is missing for that. Or should I look for some framework like rikers ?
12 replies
Félix Lesc.
Hello, is there any way to upload a file (mutlipart) with TestRequest ? I'd like to write some integration tests on file upload
2 replies
Alexander Zaitsev
Hi! What is the way to run actix's actor on tokio runtime? I've tried run_in_tokio, but actor doesn't start
22 replies
that's my example:
use actix::prelude::*;
use futures_util::stream::once;

#[rtype(result = "()")]
struct Ping;

struct MyActor;

impl StreamHandler<Ping> for MyActor {

    fn handle(&mut self, item: Ping, ctx: &mut Context<MyActor>) {

    fn finished(&mut self, ctx: &mut Self::Context) {

impl Actor for MyActor {
    type Context = Context<Self>;

    fn started(&mut self, ctx: &mut Context<Self>) {
        // add stream
        ctx.add_stream(once(async { Ping }));
async fn main() {
    let local = tokio::task::LocalSet::new();
    let sys = actix_rt::System::run_in_tokio("http_server", &local);
    //let sys = System::new("example");
    let addr = MyActor.start();

I change tokio runtime to default actix-rt runtime - all works fine
Cyprien Taque
Hi, does actix-files embeds files at compile time ?
11 replies
Nish Tahir
I've got an actix_web server setup using the actix actor system to handle tasks. What i'd like to do is log every Message that's sent/handled. Does anyone know if there is an easy way to do this?
2 replies
Gareth Lennox
I have a nice web API configured and working nicely, with diesel to hit the db, and everything is async. Now I'm trying to implement background tasks, and very quickly hit the problem that the handle function in a Handler isn't async. I've tried to wire async support in, but am struggling. In my handler, I set type Result = Future<Output = ()>, but it doesn't like that - the trait MessageResponse<MyActor, MyMessage> is not implemented for (dyn futures::Future<Output = ()> + 'static) - new to Rust, so not sure where to go from here. Anyone got any hints or guidance on how to proceed?
17 replies
Alexander Krivács Schrøder

I upgraded from actix-web 2.0.0 to 3.2.0, and while everything compiled just fine, the runtime behavior has changed in a way I don't understand. I have this code in my main():

let db_pool = database::create_db_pool();

HttpServer::new(move || {

and then I'm doing this in my middleware:

let conn = request
    .expect("couldn't get db connection from pool");

In 2.0.0, this worked as expected, in 3.2.0 I'm getting

thread 'actix-rt:worker:1' panicked at 'called `Option::unwrap()` on a `None` value', src\middleware\authentication.rs:165:18

where line 165 is the .unwrap() above. Why isn't my DbPool accessible in my middleware anymore in 3.2.0 despite still being registered with the App?

9 replies
Blas Rodriguez Irizar
Any idea why my code returns: bad hanshake
async fn index(
    req: HttpRequest,
    stream: web::Payload,
    room_manager_addr: web::Data<Addr<RoomManager>>,
) -> Result<HttpResponse, Error> {
    let room_manager_addr = (*(*room_manager_addr)).clone(); // I only want the Addr<_>
    let resp = ws::start(WebsocketSession::new(room_manager_addr), &req, stream);
    println!("{:?}", resp);

async fn main() -> std::io::Result<()> {
    let room_manager = RoomManager::new();
    let room_manager_addr = web::Data::new(room_manager.start());
    HttpServer::new(move || {
            .route("/ws/", web::get().to(index))
15 replies
Michael van Niekerk
Websocket question:
Hey all. I want to have an http endpoint be set up as a WebSocket proxy to another server. As in all the text from the local connection gets sent to/from the other server (proxy).
Any suggestion or examples how?
Simon Paitrault
Hello !
I was wondering what's the difference between using a ResponseActFuture and using ctx.wait
in which case should I use one or the other?
20 replies
Simon Paitrault

Mmmh another question. How can I define a generic on a message result:

#[rtype(result = "Addr<Subscription<S>>")]
struct CreateSubscription(SubscriptionOptions);

S is a generic used by both sender and handler. the only possible way is to use a PhantomData on the message but it feels weird. Am I missing something?

5 replies
Hi, why the C++ Dragon framework has beyond actix-web? this is unacceptable...
3 replies