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

Issue #1544 Timeout unacknowledged config management operation requests #1593

Conversation

albinsuresh
Copy link
Contributor

@albinsuresh albinsuresh commented Nov 16, 2022

Proposed changes

If a child device does not respond to a config management operation request, fail that operation in the cloud with a timeout.
This PR is split into two parts:

[x] Make the plugin stateful so that the request-response mappings can be tracked
[] Timeout unacknowledged config management operation requests

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#1544

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@albinsuresh albinsuresh force-pushed the improvement/1544/timeout-late-operations branch from c26337f to e4f8b49 Compare November 18, 2022 13:00
@albinsuresh albinsuresh marked this pull request as ready for review November 18, 2022 13:01

// Explicitly yielding to the config manager task to trigger the timeout
// as this test is running from a single threaded runtime
tokio::time::sleep(Duration::from_secs(1)).await;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately tokio::task::yield_now() didn't work here. Not quite sure why. So, resorted to tokio::time::sleep() instead.

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. However, code clarity can be improved by encapsulating the timer logic.

type TimerFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>>;

pub struct Timers<T> {
    pending_timers: FuturesUnordered<TimerFuture<T>>,
}

impl<T: Sync + Send + 'static> Timers<T> {
    pub fn new() -> Self {
        Timers {
            pending_timers: FuturesUnordered::new(),
        }
    }

    pub fn pending(&mut self) -> &mut FuturesUnordered<TimerFuture<T>> {
        &mut self.pending_timers
    }

    pub fn add_timer(&mut self, timeout: Duration, value: T) {
        self.pending_timers.push(Box::pin(sleep_and_return(timeout, value)));
    }
}

async fn sleep_and_return<T: Sync + Send + 'static>(timeout: Duration, value: T) -> T {
    sleep(timeout).await;
    value

@albinsuresh albinsuresh merged commit ef199ef into thin-edge:main Nov 21, 2022
@albinsuresh albinsuresh deleted the improvement/1544/timeout-late-operations branch November 25, 2022 08:11
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

Successfully merging this pull request may close these issues.

None yet

2 participants