diff --git a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java index ac15b1cac5..498b908e5d 100644 --- a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java +++ b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java @@ -679,7 +679,7 @@ static Mode get(Settings settings) { public void updateConfiguration(SecurityDynamicConfiguration rolesConfiguration) { try { if (rolesConfiguration != null) { - this.dlsFlsProcessedConfig.set( + DlsFlsProcessedConfig oldConfig = this.dlsFlsProcessedConfig.getAndSet( new DlsFlsProcessedConfig( DynamicConfigFactory.addStatics(rolesConfiguration.clone()), clusterService.state().metadata().getIndicesLookup(), @@ -688,6 +688,10 @@ public void updateConfiguration(SecurityDynamicConfiguration rolesConfig fieldMaskingConfig ) ); + + if (oldConfig != null) { + oldConfig.shutdown(); + } } } catch (Exception e) { log.error("Error while updating DLS/FLS configuration with {}", rolesConfiguration, e);