@@ -103,10 +103,16 @@ struct flb_aws_credentials *get_credentials_fn_profile(struct flb_aws_provider
103103 time (NULL ) >= implementation -> next_refresh )) {
104104 AWS_CREDS_DEBUG ("Retrieving credentials for AWS Profile %s" ,
105105 implementation -> profile );
106- ret = refresh_credentials (implementation , FLB_FALSE );
107- if (ret < 0 ) {
108- AWS_CREDS_ERROR ("Failed to retrieve credentials for AWS Profile %s" ,
109- implementation -> profile );
106+ if (try_lock_provider (provider ) == FLB_TRUE ) {
107+ ret = refresh_credentials (implementation , FLB_FALSE );
108+ unlock_provider (provider );
109+ if (ret < 0 ) {
110+ AWS_CREDS_ERROR ("Failed to retrieve credentials for AWS Profile %s" ,
111+ implementation -> profile );
112+ return NULL ;
113+ }
114+ } else {
115+ AWS_CREDS_WARN ("Another thread is refreshing credentials, will retry" );
110116 return NULL ;
111117 }
112118 }
@@ -152,15 +158,27 @@ struct flb_aws_credentials *get_credentials_fn_profile(struct flb_aws_provider
152158int refresh_fn_profile (struct flb_aws_provider * provider )
153159{
154160 struct flb_aws_provider_profile * implementation = provider -> implementation ;
161+ int ret = -1 ;
155162 AWS_CREDS_DEBUG ("Refresh called on the profile provider" );
156- return refresh_credentials (implementation , FLB_FALSE );
163+ if (try_lock_provider (provider ) == FLB_TRUE ) {
164+ ret = refresh_credentials (implementation , FLB_FALSE );
165+ unlock_provider (provider );
166+ return ret ;
167+ }
168+ return ret ;
157169}
158170
159171int init_fn_profile (struct flb_aws_provider * provider )
160172{
161173 struct flb_aws_provider_profile * implementation = provider -> implementation ;
174+ int ret = -1 ;
162175 AWS_CREDS_DEBUG ("Init called on the profile provider" );
163- return refresh_credentials (implementation , FLB_TRUE );
176+ if (try_lock_provider (provider ) == FLB_TRUE ) {
177+ ret = refresh_credentials (implementation , FLB_TRUE );
178+ unlock_provider (provider );
179+ return ret ;
180+ }
181+ return ret ;
164182}
165183
166184/*
@@ -234,6 +252,8 @@ struct flb_aws_provider *flb_profile_provider_create(char* profile)
234252 goto error ;
235253 }
236254
255+ pthread_mutex_init (& provider -> lock , NULL );
256+
237257 implementation = flb_calloc (1 ,
238258 sizeof (
239259 struct flb_aws_provider_profile ));
0 commit comments