diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-15 12:21:27 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-15 12:21:27 +0200 |
commit | e79953ff093c0518975111c69d16e97ccf966e20 (patch) | |
tree | 2644e1fd7b0b5f88359c42499945f8aedbe30f1c | |
parent | adaa36dbec1ce9aaafd61873b9d3d898a8c240cf (diff) | |
download | lanes-e79953ff093c0518975111c69d16e97ccf966e20.tar.gz lanes-e79953ff093c0518975111c69d16e97ccf966e20.tar.bz2 lanes-e79953ff093c0518975111c69d16e97ccf966e20.zip |
fix keeper state stack accumulating garbage in case of transfer errors
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/keeper.c | 4 | ||||
-rw-r--r-- | src/linda.c | 4 | ||||
-rw-r--r-- | tests/deadlock.lua | 2 |
5 files changed, 12 insertions, 2 deletions
@@ -1,5 +1,8 @@ | |||
1 | CHANGES: | 1 | CHANGES: |
2 | 2 | ||
3 | CHANGE 161: BGe 15-Apr-24 | ||
4 | * fix keeper state stack accumulating garbage in case of transfer errors | ||
5 | |||
3 | CHANGE 160: BGe 11-Apr-24 | 6 | CHANGE 160: BGe 11-Apr-24 |
4 | * add manual control over GC behavior in keeper states | 7 | * add manual control over GC behavior in keeper states |
5 | * update a bunch of test scripts | 8 | * update a bunch of test scripts |
@@ -77,6 +77,7 @@ test: | |||
77 | $(MAKE) basic | 77 | $(MAKE) basic |
78 | $(MAKE) cancel | 78 | $(MAKE) cancel |
79 | $(MAKE) cyclic | 79 | $(MAKE) cyclic |
80 | $(MAKE) deadlock | ||
80 | $(MAKE) errhangtest | 81 | $(MAKE) errhangtest |
81 | $(MAKE) fibonacci | 82 | $(MAKE) fibonacci |
82 | $(MAKE) fifo | 83 | $(MAKE) fifo |
diff --git a/src/keeper.c b/src/keeper.c index a1505b7..1522718 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
@@ -810,7 +810,9 @@ int keeper_call( Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, vo | |||
810 | int const Ktos = lua_gettop( K); | 810 | int const Ktos = lua_gettop( K); |
811 | int retvals = -1; | 811 | int retvals = -1; |
812 | 812 | ||
813 | STACK_GROW( K, 2); | 813 | // if we didn't do anything wrong, the keeper stack should be clean |
814 | ASSERT_L(Ktos == 0); | ||
815 | STACK_GROW(K, 2); | ||
814 | 816 | ||
815 | PUSH_KEEPER_FUNC( K, func_); | 817 | PUSH_KEEPER_FUNC( K, func_); |
816 | 818 | ||
diff --git a/src/linda.c b/src/linda.c index 2128520..d92f5f2 100644 --- a/src/linda.c +++ b/src/linda.c | |||
@@ -90,12 +90,16 @@ LUAG_FUNC( linda_protected_call) | |||
90 | Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda)); | 90 | Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda)); |
91 | lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK' | 91 | lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK' |
92 | if( KL == NULL) return 0; | 92 | if( KL == NULL) return 0; |
93 | // if we didn't do anything wrong, the keeper stack should be clean | ||
94 | ASSERT_L(lua_gettop(KL) == 0); | ||
93 | 95 | ||
94 | // retrieve the actual function to be called and move it before the arguments | 96 | // retrieve the actual function to be called and move it before the arguments |
95 | lua_pushvalue( L, lua_upvalueindex( 1)); | 97 | lua_pushvalue( L, lua_upvalueindex( 1)); |
96 | lua_insert( L, 1); | 98 | lua_insert( L, 1); |
97 | // do a protected call | 99 | // do a protected call |
98 | rc = lua_pcall( L, lua_gettop( L) - 1, LUA_MULTRET, 0); | 100 | rc = lua_pcall( L, lua_gettop( L) - 1, LUA_MULTRET, 0); |
101 | // whatever happens, the keeper state stack must be empty when we are done | ||
102 | lua_settop(KL, 0); | ||
99 | 103 | ||
100 | // release the keeper | 104 | // release the keeper |
101 | keeper_release( K); | 105 | keeper_release( K); |
diff --git a/tests/deadlock.lua b/tests/deadlock.lua index 73d7ccb..c85d99f 100644 --- a/tests/deadlock.lua +++ b/tests/deadlock.lua | |||
@@ -1,7 +1,7 @@ | |||
1 | -- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked | 1 | -- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked |
2 | -- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 | 2 | -- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 |
3 | 3 | ||
4 | local lanes = require('lanes').configure() | 4 | local lanes = require('lanes').configure{with_timers=false} |
5 | local linda = lanes.linda "deadlock_linda" | 5 | local linda = lanes.linda "deadlock_linda" |
6 | 6 | ||
7 | print "let's begin" | 7 | print "let's begin" |