Can you provide full error message? It's unclear from your code where dyn ResponseError is coming from.
dyn ResponseError is not thread-safe. It should have been declared as dyn ResponseError + Send, which allows it to be used on another thread. Sometimes it's an omission that can be fixed easily by adding + Send to types, but sometimes it's intentional and the function using it wants to prevent you from using it. So more context is needed to see what's going on.
It also matters whether you're using .await after locking the Mutex. That's a dangerous combination — mutex must be unlocked before yielding to await points. Otherwise it will stay locked even when the function isn't executing.
error[E0277]: `(dyn actix_web::ResponseError + 'static)` cannot be sent between threads safely
--> src/main.rs:395:14
|
395 | addr.send(MyMsg::new());
| ^^^^ `(dyn actix_web::ResponseError + 'static)` cannot be sent between threads safely
|
= help: the trait `std::marker::Send` is not implemented for `(dyn actix_web::ResponseError + 'static)`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<(dyn actix_web::ResponseError + 'static)>`
= note: required because it appears within the type `std::boxed::Box<(dyn actix_web::ResponseError + 'static)>`
= note: required because it appears within the type `actix_web::Error`
= note: required because it appears within the type `std::result::Result<std::string::String, actix_web::Error>`
That Error is not your error type, but Actix-web's temporary, non-thread safe type. Don't use it for your errors. Define your own which is some simple type that can be sent across threads. If you have to return an Actix-web response with Actix-web's error somewhere, then convert your error type to Actix's error at the very last moment, so that it won't have to travel between threads.