nervosnetwork / tentacle

A multiplexed p2p network framework that supports custom protocols
https://docs.rs/tentacle
MIT License
54 stars 24 forks source link

Bugs when setting the service timeout to 0 or a very large value #284

Closed doitian closed 3 years ago

doitian commented 3 years ago

In ServiceBuilder, if the timeout is set to 0:

        let mut app_service = ServiceBuilder::default()
            .key_pair(key_pair)
            .timeout(std::time::Duration::new(0, 0))
            .build(AppServiceHandle);

The dialing always fails.

If the timeout is set to very large, e.g.,

        let mut app_service = ServiceBuilder::default()
            .key_pair(key_pair)
            .timeout(std::time::Duration::new(u64::MAX, 0))
            .build(AppServiceHandle);

The process panicked because of the error:

thread 'main' panicked at 'overflow when adding duration to instant', library/std/src/time.rs:368:33
driftluo commented 3 years ago

This is expected behavior, and Tentacle cannot prevent users from doing strange things like this

doitian commented 3 years ago

For the timeout, I think we can use saturating_add to prevent the overflow. Just a little improvement.

driftluo commented 3 years ago

For the timeout, I think we can use saturating_add to prevent the overflow. Just a little improvement.

https://github.com/tokio-rs/tokio/blob/master/tokio/src/time/timeout.rs#L52 The addition of timeout depends on the implementation of the runtime library