Skip to content

Commit

Permalink
Merge pull request #159 from appgate/fix-race-condition
Browse files Browse the repository at this point in the history
Fix race condition
  • Loading branch information
lepiolet authored Nov 29, 2023
2 parents d60b3aa + d48cdfb commit 238efc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-push-injector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get commit short hash
run: echo GIT_COMMIT=$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_ENV

- name: Build cached layer
uses: docker/build-push-action@v5
with:
Expand All @@ -58,6 +61,7 @@ jobs:
push: ${{ inputs.push }}
tags: |
ghcr.io/${{ github.repository }}/sdp-device-id-service:${{ env.VERSION }}
ghcr.io/${{ github.repository }}/sdp-device-id-service:${{ env.VERSION }}-${{ env.GIT_COMMIT }}
ghcr.io/${{ github.repository }}/sdp-device-id-service:latest
- name: Build sdp-identity-service
Expand All @@ -69,6 +73,7 @@ jobs:
push: ${{ inputs.push }}
tags: |
ghcr.io/${{ github.repository }}/sdp-identity-service:${{ env.VERSION }}
ghcr.io/${{ github.repository }}/sdp-identity-service:${{ env.VERSION }}-${{ env.GIT_COMMIT }}
ghcr.io/${{ github.repository }}/sdp-identity-service:latest
- name: Build sdp-injector
Expand All @@ -80,4 +85,5 @@ jobs:
push: ${{ inputs.push }}
tags: |
ghcr.io/${{ github.repository }}/sdp-injector:${{ env.VERSION }}
ghcr.io/${{ github.repository }}/sdp-injector:${{ env.VERSION }}-${{ env.GIT_COMMIT }}
ghcr.io/${{ github.repository }}/sdp-injector:latest
17 changes: 12 additions & 5 deletions sdp-identity-service/src/identity_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ use crate::identity_creator::IdentityCreatorProtocol;
use crate::service_candidate_watcher::ServiceCandidateWatcherProtocol;

logger!("IdentityManager");


const N_WATCHERS: u8 = 2;

/// Trait that represents the pool of ServiceUser entities
/// We can pop and push ServiceUser entities
trait ServiceUsersPool {
Expand Down Expand Up @@ -375,7 +379,7 @@ impl IdentityManagerRunner<ServiceLookup, ServiceIdentity> {
external_queue_tx: Option<&Sender<IdentityManagerProtocol<F, ServiceIdentity>>>,
) -> () {
info!("Starting Identity Manager");
let mut deployment_watcher_ready = false;
let mut deployment_watchers_ready: u8 = 0;
let mut identity_creator_ready = false;
let mut existing_service_candidates: HashSet<String> = HashSet::new();
let mut missing_service_candidates: HashMap<String, F> = HashMap::new();
Expand Down Expand Up @@ -566,7 +570,7 @@ impl IdentityManagerRunner<ServiceLookup, ServiceIdentity> {
IdentityManagerProtocol::IdentityCreatorReady => {
info!("IdentityCreator is ready");
identity_creator_ready = true;
if deployment_watcher_ready {
if deployment_watchers_ready == N_WATCHERS {
info!("IdentityManager is ready");
if let Err(e) = identity_manager_tx
.send(IdentityManagerProtocol::IdentityManagerReady)
Expand All @@ -583,8 +587,8 @@ impl IdentityManagerRunner<ServiceLookup, ServiceIdentity> {
}
IdentityManagerProtocol::DeploymentWatcherReady => {
info!("DeploymentWatcher is ready");
deployment_watcher_ready = true;
if identity_creator_ready {
deployment_watchers_ready += 1;
if deployment_watchers_ready == N_WATCHERS && identity_creator_ready {
if let Err(e) = identity_manager_tx
.send(IdentityManagerProtocol::IdentityManagerReady)
.await
Expand Down Expand Up @@ -1806,7 +1810,8 @@ mod tests {
.await.expect("Unable to send message!");
// Notify that IdentityCreator is ready
tx.send(IdentityManagerProtocol::IdentityCreatorReady).await.expect("Unable to send message!");
// Notify the DeploymentWatcher is ready
// We expect 2 DeploymentWatchers to report readiness
tx.send(IdentityManagerProtocol::DeploymentWatcherReady).await.expect("Unable to send message!");
tx.send(IdentityManagerProtocol::DeploymentWatcherReady).await.expect("Unable to send message!");
let mut extra_credentials_expected: HashSet<String> = HashSet::from_iter((1 .. 12).map(|i| format!("service_user_id{}", i)).collect::<Vec<_>>());
for _ in 1 .. 12 {
Expand Down Expand Up @@ -1839,6 +1844,8 @@ mod tests {
assert_message!(m :: IdentityManagerProtocol::IdentityManagerStarted in watcher_rx);
let tx = identity_manager_tx.clone();
tx.send(IdentityManagerProtocol::IdentityCreatorReady).await.expect("Unable to send message!");
// We expect 2 DeploymentWatchers to report readiness
tx.send(IdentityManagerProtocol::DeploymentWatcherReady).await.expect("Unable to send message!");
tx.send(IdentityManagerProtocol::DeploymentWatcherReady).await.expect("Unable to send message!");
// Syncing UserCredentials log message
assert_message!(m :: IdentityManagerProtocol::IdentityManagerDebug(_) in watcher_rx);
Expand Down

0 comments on commit 238efc3

Please sign in to comment.