From 0e1fc261f1e2652aa2c5ec3bf4f793f7898da6e0 Mon Sep 17 00:00:00 2001 From: "tung.tq" Date: Thu, 12 Oct 2023 09:23:38 +0700 Subject: [PATCH] Avoid Clear All Callback Segments --- go.mod | 2 +- go.sum | 4 ++-- session.go | 6 +++++- session_test.go | 20 +++++++++++++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 2d35190..429e98b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/QuangTung97/memproxy go 1.19 require ( - github.com/QuangTung97/go-memcache v1.1.1-0.20231010112106-2412156d4079 + github.com/QuangTung97/go-memcache v1.2.0 github.com/google/btree v1.1.2 github.com/matryer/moq v0.3.0 github.com/mgechev/revive v1.3.1 diff --git a/go.sum b/go.sum index 91be420..d27b734 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo= -github.com/QuangTung97/go-memcache v1.1.1-0.20231010112106-2412156d4079 h1:lKKBIf2sFHHnlyGhd2E1pr4rEbjjhQB5wso6Eb+TwuM= -github.com/QuangTung97/go-memcache v1.1.1-0.20231010112106-2412156d4079/go.mod h1:bInH+oopFx83sRE0DaLVuXc6t3c6DsapM3Y7B7IUpOg= +github.com/QuangTung97/go-memcache v1.2.0 h1:LePkaWc4iGil1EzT/c7XzgAXo+sGiGfXoWA5o572+0U= +github.com/QuangTung97/go-memcache v1.2.0/go.mod h1:bInH+oopFx83sRE0DaLVuXc6t3c6DsapM3Y7B7IUpOg= github.com/aclements/go-gg v0.0.0-20170118225347-6dbb4e4fefb0/go.mod h1:55qNq4vcpkIuHowELi5C8e+1yUHtoLoOUR9QU5j7Tes= github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g= github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY= diff --git a/session.go b/session.go index 252016d..9ccc78c 100644 --- a/session.go +++ b/session.go @@ -270,6 +270,10 @@ func getCallbackSegment() *callbackSegment { } func putCallbackSegment(s *callbackSegment) { - *s = callbackSegment{} + s.next = nil + for i := 0; i < s.size; i++ { + s.funcs[i] = CallbackFunc{} + } + s.size = 0 callbackSegmentPool.Put(s) } diff --git a/session_test.go b/session_test.go index ee0284d..cc5d579 100644 --- a/session_test.go +++ b/session_test.go @@ -804,7 +804,21 @@ func TestCallbackSegment(t *testing.T) { func TestCallbackSegmentPool(t *testing.T) { t.Run("normal", func(t *testing.T) { x := getCallbackSegment() - x.size = 14 + x.size = 3 + x.next = x + + num1 := 10 + num2 := 10 + + x.funcs[0] = CallbackFunc{ + Object: unsafe.Pointer(&num1), + } + x.funcs[2] = CallbackFunc{ + Object: unsafe.Pointer(&num2), + } + x.funcs[3] = CallbackFunc{ + Object: unsafe.Pointer(&num2), + } oldPtr := unsafe.Pointer(x) @@ -812,7 +826,11 @@ func TestCallbackSegmentPool(t *testing.T) { x = getCallbackSegment() assert.Equal(t, 0, x.size) + assert.Nil(t, x.next) + assert.Nil(t, x.funcs[0].Object) + assert.Nil(t, x.funcs[2].Object) fmt.Println("POINTERS EQUAL:", oldPtr == unsafe.Pointer(x)) + fmt.Println("SHOULD NOT NIL:", x.funcs[3].Object) }) }