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 increase the max frame size? #306

Closed
zhengyi-yang opened this issue Jul 6, 2020 · 18 comments
Closed

How to increase the max frame size? #306

zhengyi-yang opened this issue Jul 6, 2020 · 18 comments

Comments

@zhengyi-yang
Copy link

I have encountered the error of ClientHandler errored out: frame size too big, how can I increase the max frame size in tarpc?

@tikue
Copy link
Collaborator

tikue commented Jul 6, 2020

Hi! Which transport/serialization protocol are you using?

@zhengyi-yang
Copy link
Author

I'm using bincode

@henrycg
Copy link

henrycg commented Jul 9, 2020

+1 on this question. It would be great to have some example code showing how to increase the frame size (whether for JSON or bincode).

@tikue
Copy link
Collaborator

tikue commented Jul 9, 2020

Sorry for another clarification -- is this via tokio-serde? The reason I ask is because it may be a question for them. I suspect that tokio-serde's bincode codec doesn't currently support modifying the frame size.

@henrycg
Copy link

henrycg commented Jul 9, 2020

Yes, I am just following the example code here. It looks like there is probably a way to make this work by somehow calling this function. Increasing the max frame size may not be strictly a tarpc problem/issue, but if it's easy to do, it would be great to have some example code documenting how.

If I figure out a clean way to increase the maximum frame size, I can submit a PR. If you know of a simple way to do it, that would be great too.

@tikue
Copy link
Collaborator

tikue commented Jul 9, 2020

I'll do a bit of investigation, but my hope is to do it via tokio-serde -- if you get to it before me, I'd be very thankful for a PR with an example of how to do this!

@awaited-hare
Copy link

Also encountered this. Has anyone figured out something?

@tikue
Copy link
Collaborator

tikue commented Aug 18, 2020

It will be possible to do this via tokio-serde once carllerche/tokio-serde#17 is merged. It would look something like this:

tarpc::serde_transport::tcp::listen(addr, || {
    tokio_serde::Bincode::from(
        // Configure your preferred frame size here.
        bincode::options()
            // 2^32 bytes
            .with_limit(4294967296)
    )
})

Edit: I pushed a branch with an example of this. If you want to try it yourself. you'll need to modify your Cargo.toml to point to my branch of tokio-serde.

@awaited-hare
Copy link

awaited-hare commented Aug 18, 2020

It will be possible to do this via tokio-serde once carllerche/tokio-serde#17 is merged. It would look something like this:

tarpc::serde_transport::tcp::listen(addr, || {
    tokio_serde::Bincode::from(
        // Configure your preferred frame size here.
        bincode::options()
            // 2^32 bytes
            .with_limit(4294967296)
    )
})

Edit: I pushed a branch with an example of this. If you want to try it yourself. you'll need to modify your Cargo.toml to point to my branch of tokio-serde.

Thanks! After overriding tokio-serde dependency to your git repo, I still get a bunch of ClientHandler errored out: frame size too big (always printed on the server side). Any possible reason?

Client:

    let transport = tarpc::serde_transport::tcp::connect(
        server_addr
            .parse::<std::net::SocketAddr>()
            .unwrap_or_else(|_| {
                panic!("cannot parse server_addr {:?}", server_addr);
            }),
        tokio_serde::formats::Bincode::from(bincode::options().with_no_limit()),
    )
    .await
    .unwrap();

    let client = MyServiceClient::new(tarpc::client::Config::default(), transport)
        .spawn()
        .unwrap();

Server:

    tarpc::serde_transport::tcp::listen(
        (std::net::IpAddr::from([0, 0, 0, 0]), config.server_port),
        || tokio_serde::formats::Bincode::from(bincode::options().with_no_limit()),
    )
    .await?
    .filter_map(|r| futures::future::ready(r.ok()))
    .map(tarpc::server::BaseChannel::with_defaults)
    .map(|channel| {
        let server = MyServer {
            socket_addr: channel.as_ref().peer_addr().unwrap(),
        };
        channel.respond_with(server.serve()).execute()
    })
    .buffer_unordered(20)
    .for_each(|_| async {})
    .await;

@awaited-hare
Copy link

@tikue It seems that bincode's default byte limit is Infinite, so the error may not come from bincode?

@tikue
Copy link
Collaborator

tikue commented Aug 18, 2020

Ah! You're totally right. I think it's coming from the hard-coded LengthDelimitedCodec in tarpc::serde_framed::Transport. I'm sorry about that! It shouldn't be too hard to add another method that allows configuring the length-delimited codec.

@awaited-hare
Copy link

Ah! You're totally right. I think it's coming from the hard-coded LengthDelimitedCodec in tarpc::serde_framed::Transport. I'm sorry about that! It shouldn't be too hard to add another method that allows configuring the length-delimited codec.

Thanks :) It seems to be this line: https://github.com/google/tarpc/blob/v0.21.1/tarpc/src/serde_transport/mod.rs#L102.

Not sure about where to appropriately add the method though.

awaited-hare pushed a commit to awaited-hare/tarpc that referenced this issue Aug 18, 2020
awaited-hare pushed a commit to awaited-hare/tarpc that referenced this issue Aug 18, 2020
@tikue
Copy link
Collaborator

tikue commented Aug 18, 2020

I pushed a commit to master that exposes the framing config options. I updated the example service to show how to do this. Let me know if it fixes it :)

@awaited-hare
Copy link

I'm still getting ClientHandler errored out: frame size too big. Trying to construct a simple example.

@tikue
Copy link
Collaborator

tikue commented Aug 18, 2020

As far as I can tell, it's working for me locally. I can set the frame size very small and force the client requests to error, and when I set the frame size bigger, the errors stop.

@awaited-hare
Copy link

As far as I can tell, it's working for me locally. I can set the frame size very small and force the client requests to error, and when I set the frame size bigger, the errors stop.

Turns out it works fines. I was still getting frame size too big because there's an HTTP client querying the same port (and tarpc doesn't know it is an HTTP client, and still interpret the first 4 bytes as the frame lengths, which could be very large).

Thanks a lot for your help! @tikue

@tikue
Copy link
Collaborator

tikue commented Aug 18, 2020

Very glad to hear it's working! I'll publish a version later today.

@tikue
Copy link
Collaborator

tikue commented Aug 20, 2020

I just published v0.22.0 which incorporates this change.

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

4 participants