Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch and redirect to 500 error in a crash on actix 2? #1504

Closed
mamcx opened this issue May 12, 2020 · 1 comment
Closed

How to catch and redirect to 500 error in a crash on actix 2? #1504

mamcx opened this issue May 12, 2020 · 1 comment

Comments

@mamcx
Copy link

mamcx commented May 12, 2020

This is happening after I migrate to 2. When a crash happened (a unwarp gone wrong, for example), the error handlers not catch it, the error backtrace is repeated * thread number, the browser answer with a connection reset:

May 12 10:21:22.050 INFO Starting "actix-web-service-127.0.0.1:5000" service on 127.0.0.1:5000, version: 0.2.0
thread 'actix-rt:worker:0' panicked at 'internal error: entered unreachable code', server/src/core.rs:92:9
stack backtrace:
0: 0x1083a2cbf - backtrace::backtrace::libunwind::trace::h6428452ebf6513c0
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
1: 0x1083a2cbf - backtrace::backtrace::trace_unsynchronized::h8bc3f3c9d1e99578
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
.. a wall of errors here, repeated 6 times (I have 6 cores)

fn error_page<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> 

#[actix_rt::main]
async fn main() -> Result<(), CoreErr> {
    let _scope_guard = corelib::slog_scope::set_global_logger(LOG.clone());
    corelib::slog_stdlog::init_with_level(log::Level::Info).unwrap();
    let pool = Db::open_server(None)?;

    HttpServer::new(move || {
        App::new()
            .data(pool.clone())
            .wrap(middleware::NormalizePath)
            .wrap(middleware::Compress::default())
            .wrap(
                Cors::new()
                    .supports_credentials()
                    .max_age(3600)
                    .finish(),
            )
            .wrap(
                ErrorHandlers::new()
                    .handler(http::StatusCode::NOT_FOUND, error_page)
                    .handler(http::StatusCode::INTERNAL_SERVER_ERROR, error_page),
            )
            .wrap(IdentityService::new(
                CookieIdentityPolicy::new(...)
                    .name("auth")
                    .max_age(60 * 60 * 24) //1 dias
                    .secure(!is_debug()),
            ))
            .wrap(middleware::Logger::default()) //always last
            .service(web::resource("/login").to(admin::login))
       })
    .bind("127.0.0.1:5000")?
    .run()
    .await
    .map_err(|source| CoreErr::IOError { source })
}
@robjtede
Copy link
Member

robjtede commented May 12, 2020

see recent discussion about it here:
#1501

tl;dr: handle your errors

@mamcx mamcx closed this as completed May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants