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

Error trying to upload a "big" torrent file #255

Closed
josecelano opened this issue Aug 15, 2023 · 2 comments · Fixed by #258
Closed

Error trying to upload a "big" torrent file #255

josecelano opened this issue Aug 15, 2023 · 2 comments · Fixed by #258
Labels
Bug Incorrect Behavior Easy Good for Newcomers

Comments

@josecelano
Copy link
Member

josecelano commented Aug 15, 2023

I'm testing with real torrents like this:

http://academictorrents.com/details/b8287ebfa04f879b048d4d4404108cf3e8014352

I get a Bad Request response trying to upload the torrent to the backend. I think the problem is the torrent is too big (2.2MB).

I've been debugging, and the error is thrown here.

                while let Some(chunk) = field.chunk().await.map_err(|_| (ServiceError::BadRequest))? {
                    torrent_cursor.write_all(&chunk)?;
                }

I am still determining the reason. I must first check if the backend is receiving the whole torrent data.

@josecelano josecelano added Bug Incorrect Behavior Easy Good for Newcomers labels Aug 15, 2023
@josecelano
Copy link
Member Author

The default body size limit is 2 MB.

You can increase it by adding a layer to the router:

router.layer(DefaultBodyLimit::max(5_242_880))

Full router config:

pub fn router(app_data: Arc<AppData>) -> Router {
    let v1_api_routes = Router::new()
        .route("/", get(about_page_handler).with_state(app_data.clone()))
        .nest("/user", user::routes::router(app_data.clone()))
        .nest("/about", about::routes::router(app_data.clone()))
        .nest("/category", category::routes::router(app_data.clone()))
        .nest("/tag", tag::routes::router_for_single_resources(app_data.clone()))
        .nest("/tags", tag::routes::router_for_multiple_resources(app_data.clone()))
        .nest("/settings", settings::routes::router(app_data.clone()))
        .nest("/torrent", torrent::routes::router_for_single_resources(app_data.clone()))
        .nest("/torrents", torrent::routes::router_for_multiple_resources(app_data.clone()))
        .nest("/proxy", proxy::routes::router(app_data.clone()));

    let router = Router::new()
        .route("/", get(about_page_handler).with_state(app_data))
        .nest(&format!("/{API_VERSION_URL_PREFIX}"), v1_api_routes);

    let router = if env::var(ENV_VAR_CORS_PERMISSIVE).is_ok() {
        router.layer(CorsLayer::permissive())
    } else {
        router
    };

    router.layer(DefaultBodyLimit::max(5_242_880))
}

For now, I'm going to increase it to 10MB. I will open a new issue to add a config option to define this limit.

@josecelano
Copy link
Member Author

I've tested it with a 4.7MB torrent containing 39963 files.

c398a571976c78d346c325bd75c47b82edf6124e.zip

@josecelano josecelano linked a pull request Aug 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect Behavior Easy Good for Newcomers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant