From 0e75a94bdeea801f42c13d324a2b22212923e278 Mon Sep 17 00:00:00 2001 From: shuaichen Date: Wed, 27 Nov 2024 06:51:27 -0800 Subject: [PATCH] out_stackdriver bug fix: return cached token when current_timestamp is less than cached_expiration (#9652) * out_stackdriver: return cached token when current_timestamp is less than cached_expiration. Signed-off-by: shuaichen * stackdriver: revert log line change Signed-off-by: Braydon Kains <93549768+braydonk@users.noreply.github.com> --------- Signed-off-by: shuaichen Signed-off-by: Braydon Kains <93549768+braydonk@users.noreply.github.com> Co-authored-by: Braydon Kains <93549768+braydonk@users.noreply.github.com> Signed-off-by: AdheipSingh --- plugins/out_stackdriver/stackdriver.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 903bffce98d..99ef657a0b4 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -357,6 +357,7 @@ static flb_sds_t get_google_token(struct flb_stackdriver *ctx) int ret = 0; flb_sds_t output = NULL; time_t cached_expiration = 0; + time_t current_timestamp = 0; ret = pthread_mutex_trylock(&ctx->token_mutex); if (ret == EBUSY) { @@ -369,7 +370,9 @@ static flb_sds_t get_google_token(struct flb_stackdriver *ctx) */ output = oauth2_cache_to_token(); cached_expiration = oauth2_cache_get_expiration(); - if (time(NULL) >= cached_expiration) { + current_timestamp = time(NULL); + + if (current_timestamp < cached_expiration) { return output; } else { /*