Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 2/2] fiber: destroy fiber.storage created by iproto
Date: Fri, 13 Dec 2019 00:37:57 +0100	[thread overview]
Message-ID: <1d40cedb-c631-a420-2391-1f27a5a07fe5@tarantool.org> (raw)
In-Reply-To: <20191212000047.GL1214@tarantool.org>

Thanks for the review!

>> diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
>> index 00ae8cded..d89c640aa 100644
>> --- a/src/lib/core/fiber.c
>> +++ b/src/lib/core/fiber.c
>> @@ -787,7 +801,7 @@ static void
>>  fiber_reset(struct fiber *fiber)
>>  {
>>  	rlist_create(&fiber->on_yield);
>> -	rlist_create(&fiber->on_stop);
>> +	rlist_create(&fiber->on_cleanup);
>>  	fiber->flags = FIBER_DEFAULT_FLAGS;
>>  #if ENABLE_FIBER_TOP
>>  	clock_stat_reset(&fiber->clock_stat);
>> @@ -856,8 +870,7 @@ fiber_loop(MAYBE_UNUSED void *data)
>>  		       assert(f != fiber);
>>  		       fiber_wakeup(f);
>>  	        }
>> -		if (! rlist_empty(&fiber->on_stop))
>> -			trigger_run(&fiber->on_stop, fiber);
>> +	        fiber_cleanup(fiber);
> 
> I see you dropped the if above and fiber_cleanup doesn't have any
> corresponding within. Is this removal an intentional one?

Yes. This is because trigger_run works fine with empty
rlist, so this check was useless.

> 
> Minor: There is a mess with whitespace above. Feel free to ignore the
> remark, since indentation was broken before your changes. I blamed
> several lines and it looks more like a ridiculous code style, and not a
> problem with editor. Thereby you just implicitly continue the mix.

Wow, good catch! I didn't notice it in git diff nor in the
editor. Fixed.

> 
>>  		/* reset pending wakeups */
>>  		rlist_del(&fiber->state);
>>  		if (! (fiber->flags & FIBER_IS_JOINABLE))
>> diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h
>> index c5b975513..21fff8f88 100644
>> --- a/src/lib/core/fiber.h
>> +++ b/src/lib/core/fiber.h
>> @@ -458,8 +458,17 @@ struct fiber {
>>  
>>  	/** Triggers invoked before this fiber yields. Must not throw. */
>>  	struct rlist on_yield;
>> -	/** Triggers invoked before this fiber stops.  Must not throw. */
>> -	struct rlist on_stop;
>> +	/**
>> +	 * Triggers invoked before this fiber is
>> +	 * stopped/reset/recycled/destroyed/reused. In other
>> +	 * words, each time when the fiber has finished execution
>> +	 * of a request.
>> +	 * In particular, for fibers not from fiber pool the
>> +	 * cleanup is done before destroy and death.
>> +	 * Pooled fibers are cleaned up after each request, even
>> +	 * if they are never destroyed.
>> +	 */
>> +	struct rlist on_cleanup;
> 
> Minor: both trigger lists above has the "Must not throw" note. Does the
> introduced list respect this rule? Please, adjust the comment if yes.

Nope. These 'must not throw' are outdated. Our triggers does not
throw errors anymore by design. So I deleted it from the updated
comment.

>>  	/**
>>  	 * The list of fibers awaiting for this fiber's timely
>>  	 * (or untimely) death.
>> diff --git a/src/lua/fiber.c b/src/lua/fiber.c
>> index a7b75f9bf..4d2828f1c 100644
>> --- a/src/lua/fiber.c
>> +++ b/src/lua/fiber.c
>> @@ -606,12 +601,43 @@ lbox_fiber_name(struct lua_State *L)
>>  	}
>>  }
>>  
>> +/**
>> + * Trigger invoked when the fiber has finished execution of its
>> + * current request. Only purpose - delete storage.lua.ref keeping
>> + * a reference of Lua fiber.storage object. Unlike Lua stack,
>> + * Lua fiber storage may be created not only for fibers born from
>> + * Lua land. For example, an IProto request may execute a Lua
>> + * function, which can create the storage. Trigger guarantees,
>> + * that even for non-Lua fibers the Lua storage is destroyed.
>> + */
>> +static int
>> +lbox_fiber_on_cleanup(struct trigger *trigger, void *event)
>> +{
>> +	struct fiber *f = (struct fiber *) event;
>> +	int storage_ref = f->storage.lua.ref;
>> +	assert(storage_ref > 0);
>> +	luaL_unref(tarantool_L, LUA_REGISTRYINDEX, storage_ref);
>> +	f->storage.lua.ref = 0;
> 
> Though 0 value is specific "ref" (a table slot, where the LRU ref is
> stored) and this value cannot be yield from luaL_ref. Please, consider
> using LUA_NOREF value for such cases, since it's being provided by Lua
> and lua_unref does nothing for it, as well as for LUA_REFNIL.

Thanks, didn't know about these constants.

===================================================================
 	assert(storage_ref > 0);
 	luaL_unref(tarantool_L, LUA_REGISTRYINDEX, storage_ref);
-	f->storage.lua.ref = 0;
+	f->storage.lua.ref = LUA_NOREF;
 	trigger_clear(trigger);
 	free(trigger);
===================================================================

  reply	other threads:[~2019-12-12 23:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-08 19:28 [Tarantool-patches] [PATCH 0/2] Fiber storage leak Vladislav Shpilevoy
2019-12-08 19:28 ` [Tarantool-patches] [PATCH 1/2] fiber: unref fiber.storage via global Lua state Vladislav Shpilevoy
2019-12-11 23:57   ` Igor Munkin
2019-12-12  8:50     ` Konstantin Osipov
2019-12-12 23:38     ` Vladislav Shpilevoy
2019-12-13 10:44       ` Igor Munkin
2019-12-08 19:28 ` [Tarantool-patches] [PATCH 2/2] fiber: destroy fiber.storage created by iproto Vladislav Shpilevoy
2019-12-09  7:21   ` Konstantin Osipov
2019-12-09 23:31     ` Vladislav Shpilevoy
2019-12-10  8:21       ` Konstantin Osipov
2019-12-10  8:32   ` Konstantin Osipov
2019-12-10 22:59     ` Vladislav Shpilevoy
2019-12-11  7:08       ` Konstantin Osipov
2019-12-11 21:23         ` Vladislav Shpilevoy
2019-12-12  0:00           ` Igor Munkin
2019-12-12 23:37             ` Vladislav Shpilevoy [this message]
2019-12-13 13:35               ` Igor Munkin
2019-12-12  8:46           ` Konstantin Osipov
2019-12-13  0:02             ` Vladislav Shpilevoy
2019-12-13  7:58               ` Konstantin Osipov
2019-12-13 23:11                 ` Vladislav Shpilevoy
2019-12-14 12:26                   ` Konstantin Osipov
2019-12-14 12:30                     ` Konstantin Osipov
2019-12-14 12:33                       ` Konstantin Osipov
2019-12-14 16:49                         ` Vladislav Shpilevoy
2019-12-14 20:59                           ` Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d40cedb-c631-a420-2391-1f27a5a07fe5@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/2] fiber: destroy fiber.storage created by iproto' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox