Safeguarding of important minetest.after functions

User avatar
MirceaKitsune
Member
 
Posts: 809
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Safeguarding of important minetest.after functions

by MirceaKitsune » Mon Jun 29, 2015 14:29

https://github.com/minetest/minetest/issues/2856

I've come across a considerable limitation while working on one of my mods, which might affect many mods that use delays to schedule important tasks on the server.

I have a mod which schedules a Lua function to execute after several seconds, by putting it in a minetest.after(#) function. It's essential that the delayed functions are eventually ran, as their effect is permanent on the server and there are supposed to be no gaps. However there is no way to prevent the server from shutting down before a minetest.after function gets to finish. Further more, if the server crashes before the function executes, it will be gone before it ever runs.

I would like to know if a way to work around this problem can be found. Personally, I suggest an additional parameter to the minetest.after function, which (when true) marks the call as persistent. If a persistent minetest.after function exists, two things will happen:

- The server does not shut down before the function runs. If someone issues a shutdown command, the server will remain in "shutting down" state until the delayed function finished executing. In addition to this, or alternatively to this:

- When initialized, the function should be stored in a suspended state in the world directory (possibly in a special database) from which it's removed once it executes. If the server crashes before the function runs, the function is retrieved from here once the server is back up, and put back into the queue using the best possible estimation of when the server crashed to know how much time it had left. minetest.after functions using this should of course not contain references to anything that changes between server restarts, just parameters that are constant (like positions)... this is however the mod creator's responsibility.
 

Ivà
Member
 
Posts: 115
Joined: Sun Feb 22, 2015 07:11
GitHub: melzua
IRC: melzua
In-game: melzua

Re: Safeguarding of important minetest.after functions

by Ivà » Mon Jun 29, 2015 16:08

About the server shutting down before the functions runs, maybe what plants_lib do is useful to you:
viewtopic.php?f=11&t=3898&start=200#p171208 (look at the second paragraph).
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Safeguarding of important minetest.after functions

by Wuzzy » Mon Jun 29, 2015 19:46

I completely understand your issue and feature request.

I have had this issue when developing the mod “Player Effects”. I just manually wrote the entire state of all effects (including the timers) into a file in the world directory on shutdown and also in regular intervals (for added security against crashes).

This is a workaround, it works more or less. But I would love to see the engine doing this sort of job for me, it could probably do it more efficient and secure than with my little script.

In the meanwhile, I can also think of two theoretical alternatives to using minetest.after:
  • Regularily check against the gametime, you can get it with minetest.get_gametime(). Note that only full seconds count.
  • Use minetest.register_on_globalstep and its dtime timer to update some timer variable in your script and regularily check against some limit.

- The server does not shut down before the function runs. If someone issues a shutdown command, the server will remain in "shutting down" state until the delayed function finished executing.


This sounds like a potential troublemaker because the server could stay in limbo if the timer was set for a long time. I also am not sure if there is even an use case where the server *must* stay up until the server has been run. Could you think of any use case where the server *must* stay up AND the other alternative would not be feasible?

I like your other solution with the additional parameter much more.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Safeguarding of important minetest.after functions

by rubenwardy » Mon Jun 29, 2015 20:48

Iirc, minetest.after is entirely Lua based. It runs off a global step callback.

https://github.com/minetest/minetest/bl ... lua#L7-L64
 

Hybrid Dog
Member
 
Posts: 2460
Joined: Thu Nov 01, 2012 12:46

Re: Safeguarding of important minetest.after functions

by Hybrid Dog » Thu Jul 02, 2015 15:34

it's really annoying when exiting minetest takes longer if plantlife increases the delay l need to wait until the minetest window disappears from my screen
btw, this should delay functions only if it's not lagging
https://github.com/HybridDog/function_delayer
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 6 guests

cron