You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/10/09 09:42:26 UTC

[apisix-go-plugin-runner] branch master updated: fix: make sure the cached conf expires after the token (#44)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-go-plugin-runner.git


The following commit(s) were added to refs/heads/master by this push:
     new 7838be4  fix: make sure the cached conf expires after the token (#44)
7838be4 is described below

commit 7838be46af76d783eed460cb4a21434d7bbc9970
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Sat Oct 9 17:42:23 2021 +0800

    fix: make sure the cached conf expires after the token (#44)
---
 internal/server/server.go      | 6 ++++--
 internal/server/server_test.go | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/internal/server/server.go b/internal/server/server.go
index 6193a11..72f4a81 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -149,9 +149,11 @@ func handleConn(c net.Conn) {
 }
 
 func getConfCacheTTL() time.Duration {
+	// ensure the conf cached in the runner expires after the token in APISIX
+	amplificationFactor := 1.2
 	ttl := os.Getenv(ConfCacheTTLEnv)
 	if ttl == "" {
-		return 3600 * time.Second
+		return time.Duration(3600*amplificationFactor) * time.Second
 	}
 
 	n, err := strconv.Atoi(ttl)
@@ -159,7 +161,7 @@ func getConfCacheTTL() time.Duration {
 		log.Errorf("invalid cache ttl: %s", ttl)
 		return 0
 	}
-	return time.Duration(n) * time.Second
+	return time.Duration(float64(n)*amplificationFactor) * time.Second
 }
 
 func getSockAddr() string {
diff --git a/internal/server/server_test.go b/internal/server/server_test.go
index 9147f75..c698cb7 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -42,10 +42,10 @@ func TestGetSockAddr(t *testing.T) {
 
 func TestGetConfCacheTTL(t *testing.T) {
 	os.Unsetenv(ConfCacheTTLEnv)
-	assert.Equal(t, 3600*time.Second, getConfCacheTTL())
+	assert.Equal(t, 4320*time.Second, getConfCacheTTL())
 
 	os.Setenv(ConfCacheTTLEnv, "12")
-	assert.Equal(t, 12*time.Second, getConfCacheTTL())
+	assert.Equal(t, 14*time.Second, getConfCacheTTL())
 
 	os.Setenv(ConfCacheTTLEnv, "1a")
 	assert.Equal(t, time.Duration(0), getConfCacheTTL())