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

task: Updated to only refresh tokens of type Client #44

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions server/src/http/background_refresh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashSet, sync::Arc, time::Duration};

use crate::types::{ClientFeaturesResponse, EdgeSink, EdgeToken};
use crate::types::{ClientFeaturesResponse, EdgeSink, EdgeToken, TokenType};
use tokio::sync::{mpsc::Receiver, mpsc::Sender, RwLock};
use tracing::{info, warn};

Expand All @@ -15,11 +15,13 @@ pub async fn poll_for_token_status(
let mut write_lock = sink.write().await;
match write_lock.validate(vec![token.clone()]).await {
Ok(validated_tokens) => {
let sink_result = write_lock.sink_tokens(validated_tokens).await;
let sink_result = write_lock.sink_tokens(validated_tokens.clone()).await;
if let Err(err) = sink_result {
warn!("Couldn't sink token result: {err:?}")
} else {
let _ = feature_channel.send(token).await;
for valid in validated_tokens {
let _ = feature_channel.send(valid).await;
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to only send in filtered "client" tokens to the channel instead of sending in everything and filtering on the refresh_features method?

Copy link
Member

Choose a reason for hiding this comment

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

Occurred to me as well. I suspect we're going to tap into this from more than just this place, though, so it's nice to be defensive. Probably something for a future PR when the structure is more settled here if we only call this from the one place

}
}
}
Err(e) => {
Expand All @@ -39,7 +41,9 @@ pub async fn refresh_features(mut channel: Receiver<EdgeToken>, sink: Arc<RwLock
tokio::select! {
token = channel.recv() => { // Got a new token
if let Some(token) = token {
tokens.insert(token);
if token.token_type == Some(TokenType::Client) {
tokens.insert(token);
}
} else {
break;
}
Expand Down