• All submissions to this site are governed by Second Life Project Contribution Agreement. By submitting patches and other information using this site, you acknowledge that you have read, understood, and agreed to those terms.
Issue Details (XML | Word | Printable)

Key: SVC-1853
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Unassigned
Reporter: chorazin allen
Votes: 133
Watchers: 25
Operations

If you were logged in you would be able to see more operations.
2. Second Life Service - SVC

State of not-running scripts is not preserved over a region restart

Created: 16/Mar/08 06:16 AM   Updated: 16/Nov/09 05:48 AM
Return to search
Component/s: Scripts
Affects Version/s: 1.19.0 Server, 1.20.0 Server, 1.24 Server
Fix Version/s: None

Environment: Server-side issue on main grid
Issue Links:
Duplicate
Parent/Child
 
Relates
 

Linden Lab Issue ID: DEV-14012


 Description  « Hide
Put two scripts in an object.
Counter
integer count;

default
{
    state_entry()
    {
        llSetTimerEvent(1.0);
    }
    
    timer()
    {
        count++;
        llOwnerSay((string)count);
    }
}
Start/Stop
default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    {
        integer running=llGetScriptState("Counter");
        
        if (running)
        {
            llSetScriptState("Counter",FALSE);
            llOwnerSay("Script stopped");
        }
        else
        {
            llSetScriptState("Counter",TRUE);
            llOwnerSay("Script started");
        }
    }
}

Touch the object to see that the Counter script is started and stopped as expected. Let it run for a while, stop it, and note the last value displayed.

Now restart the region.

When the region is back, return to the object and touch it to restart the Counter.

The Counter script, which was stopped, has lost all state and will begin counting from 0 rather than the total it had previously.

Implications: This is a major headache for those situations where scripts would be stopped because they're not needed at the time or are stopped to reduce peformance impact. If a restart happens whilst they're stopped they do not resume in the same state that they were stopped.

Update 20080328...

This includes any granted Permissions, so in the crude example below, the script will lose the granted Debit permission over a restart if the script was not running at the time. Of course, if the script's owner isn't around to re-grant the permissions things get nasty.

A really good script would detect that it's unexpectedly lost permissions it had been previously granted. Most won't and will carry on regardless, which could be real nasty in the case of a script that thinks it has the Debit permission to (for example) pay out the prize in a competition.

Modified version of Counter script (I know this is crude ):-

Modified Counter
integer count;

default
{
    state_entry()
    {
        llSetTimerEvent(1.0);
        llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
    }
    
    timer()
    {
        count++;
        llOwnerSay((string)count);
        llGiveMoney(llGetOwner(),1);
    }
}


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
chorazin allen added a comment - 28/Mar/08 01:52 AM
[Added section about Permissions being similarly affected]

chorazin allen added a comment - 10/Apr/08 08:38 PM
Sill an issue for 1.20 server - updated Affects Versions to 1.20

Periapse Linden added a comment - 18/Apr/08 11:59 AM
Are you sure this is new behavior? I don't see how scripts could save state when the region restarts, but I will try to get a developer to comment.

chorazin allen added a comment - 18/Apr/08 12:18 PM
Periapse> It may have always been this way - I don't have proof that it used to work and now doesn't.

Running scripts preserve their state over a region restart (more accurately I guess their stack, heap, permissions etc are saved in the latest region snapshot and they resume with their state as at that snapshot) but this doesn't seem to be the case for scripts which had been running but were not at the time of the snapshot. Scripts not-running at the time of the snapshot are in a virgin state when set to running again after a region restart when the region has been reloaded from the snapshot.

Putting it a different way, I think region backups should include and restore state for not-running (but have been run at some point previously) scripts as well as running scripts


Periapse Linden added a comment - 18/Apr/08 12:38 PM
Ah, now I get it. Either this is a bug, or a reasonable feature request. I'll make sure it gets seen by the Studio Blighty developers.

Irene Ikarus added a comment - 21/Apr/08 09:38 AM
There is another report and already more comprehensive http://jira.secondlife.com/browse/SVC-26
It is also previous and should be noticed.
Scripts setted to not running not only reset themselves after region restarts, also when saving scripts to inventory and re-rezzing, or when crossing sim borders with a stopped script. It's not a problem of preserving the original state, if they are in the default state the state_entry() event should never be called back when the script is turned back to running. Fixing this if it was an old issue or introducing this as a new feature would incrrease the chances of developing better scripts. The present bug forces to mantain in running state scripts that store dinamic data if they are going to be derezzed or used while crossing sim borders, or at sim resets, even if there was no need to keep them active and consuming resources.

Harleen Gretzky added a comment - 21/Apr/08 11:52 AM
Actually this looks to be a duplicate of SVC-26

Periapse Linden added a comment - 29/Apr/08 12:11 PM
Thanks for the observation Harleen. I want to keep this issue open, even though it is a dupe of SVC-26, because I've been able to get some traction on it.

Babbage agrees that this is onerous, and he's triaged it onto the Blighty tasks list as something to tackle after Mono ships (or the next lull we get in working on Mono).

I'll be sure to reference the prior documentation in SVC-26 on the internal JIRA.


Sieben Ochs added a comment - 05/May/08 01:00 PM
My tip jars for one uses various scripts along with .main script to storing the data then they are turned off. And only called when a set text change is needed to be applied ,or giving pay out etc. If the sim resets while these scripts are off, the data in these scripts is also reset.

"Periapse Linden - 18/Apr/08 11:59 AM
Are you sure this is new behavior? I don't see how scripts could save state when the region restarts, but I will try to get a developer to comment. "

If this is the case then maybe allowing a new toggable flag. Such as llStoreScript(TRUE). Which would effectively allow scripts to keep their stored data on these resets. And for sim owners giving them a advanced feature to force reset of all scripts, even ones with the new flag.


Scouse Linden added a comment - 25/Jul/08 08:34 AM
I'd suggest using a state to change the script to an inactive mode instead of actually turning them off. The state of scripts should not be relied on to the level and scripts needing better persistence should use some external service perhaps using HTTP, XML-RPC or email.

chorazin allen added a comment - 25/Jul/08 08:59 AM
Going into another state is a valid workround, however extra coding is needed to start and stop listeners, timers etc.

Howver, given the decision not to fix the bug, llSetScriptState should be changed to reset a script when the script is being stopped so that behaviour is consistent whether or not a region restarts whilst the script is stopped


Ralph Doctorow added a comment - 27/Jul/08 05:49 PM
IMHO the decision not to fix this is extremely shortsighted.

What you're saying is that we can't limit server script resource usage by shutting off scripts that don't need to be running but need to preserve state. Having too many scripts running on a server absolutely kills performance, OTOH because of the limited memory available to a single script, it's often very necessary to have multiple scripts to do complex behaviors, particularly ones that need to keep anything beyond a tiny amount of data. With some design care, breaking this up into multiple scripts and only activating the ones needed at any moment get around both problems, but not if you can't rely on the state being preserved.

The suggestion to keep data outside SL is not very helpful towards limiting server loading and is too slow for many applications in any case.

It's difficult for me to see why this is such an insurmountable problem in any case. Surely, the main difference between an active and inactive script is just if it's in the scheduler queue. Active scripts keep their states, why not inactive?

I suggest you rethink this.


Strife Onizuka added a comment - 29/Jul/08 07:29 PM - edited
Just to clarify, "Resolved" does not mean that they have made a definitive, irrevocable, decision. It simply states their intention and that they are open to persuasion. (WEB-690)

Periapse Linden added a comment - 30/Jul/08 09:26 AM
Yes indeed, Strife.

Ralph - If you can attend Babbage's and Scouse's office hour on Wednesday mornings (8am, PDT) you can directly chat with the Mono devs. Alternatively we can carry on a longer latency discussion here. I will add watchers to this issue.


chorazin allen added a comment - 31/Jul/08 12:15 AM
The timing means that I can't get to the office hour, so here instead are some more detailed comments on why I believe there's still a bug to answer here.

1) There's an inconsistency in how llSetScriptState behaves. Most of the time you can stop and start a script with no data/state/permissions loss. However, if the region the non-running script is in has restarted over that period the script is in virgin condition when it comes to be restarted. Therefore, you cannot rely on llSetScriptState at all unless you back it up with detection of region restarts. If this ticket stays in 'won't be resolved' state, then llSetScriptState should be changed to always reset a script on stopping it so that behaviour is always consistent. Unexpected loss of permissions (especially DEBIT) is particularly awkward because they can't be re-established until the av that granted them can next get to the object.

2) Storing data outworld is not an option. Why?
a) The point of stopping and starting scripts is to help region performance; I don't want to go through elaborate storage and retrieval routines before and after
b) In my specific example, I wake up the stopped scripts when an avatar collides with the insides of the object; I need a startup that's consistently, reliably faster than avatar movement
c) None of the three alternatives satisify point b, specifically
i) email: email is not guaranteed to be delivered instantly, or at all
ii) xml: the issues with the loading and reliability of the xml gateway don't need repeating here
iii) html: could be made to work despite being one-way initiated, but won't result in the instant start I need, and means additional region load as the script recovers all its state and delay before the script is ready to work

3) Script operation should be intuitive, predictable and straightforward. If you stop and start a script either it should always come back how you stopped it, or always come back in a virgin state. Since this cannot be relied on at present, there currently has to be a workround in the deployed script. Currently, I detect region restarts and then reboot the whole object so that all the data and shared state is correctly distributed again (eg I have one script which never stops which owns the main listener, and it sends listen messages around by link_message, but... the other scripts need to know the channel number so that they can initiate dialogs without having to ask the always-running script to do it for them so saving one link message - ok, I could ship around the channel number with the link message but at the time I was designing the communications I thought I could rely on only having to send it around once at startup). Sure, I could use the state-based workround proposed above instead, however then I've got to have additional code to handle the effects of the state change (and, since timers aren't affected by a state change the timer routine would have to be manually stopped and restarted... which in turn means extra code to store the current timer frequency in a global variable). -> -> -> I may not be fully right in some of the technical comments made in these last 12 lines of text, but I think it demonstrates clearly why the current situation isn't fulfulling the criteria of intuitive, predicatable and straightforward - point made!

4) Not addressing this goes against considerate use of region resources. Many people (for whatever reason) just leave scripts running at full tilt whether there's anything for the script to do or not. Every running script with timers, listens or scanners will have a certain impact on a region's script bandwidth. This is a finite resource even with the improvements expected from Mono. It should be easy to pause a script until it's needed again and then do a just-in-time restart with previous state preserved. If it's not easy to do, the majority of scripters will discover the gotchas and decide it's too much hassle to think about pausing their scripts and just leave them running all the time without even bothering to do the extra code to go in and out of another state, cancel timers, etc.

5) There's advice out there that scripts should consider self-moderation, ie if they see time dilation dropping they should reduce their activities or even stop. In the scenario where a script can be stopped, forcing the script to do a burst of activity (any maybe outworld communciation) when it's preparing to stop is adding to the region load, not helping reduce it. If we assume that it's an extreme time dilation dip, it's even possible that the routines to save data will fail for some reason (timeouts exceeded for outworld response, scripts getting out of sync with one another because of message delivery delays/loss etc..)

--Chorazin


Periapse Linden added a comment - 06/Aug/08 02:03 PM
Copying Chorazin's comment into internal LL JIRA

Periapse Linden added a comment - 26/Sep/08 02:50 PM
Mono is now live. Http In is underway, and the load limiting it requires makes this issue salient again. Reopening both this and the internal JIRA for discussion and priority triage as the blighty team goes into Q4.


Strife Onizuka added a comment - 25/Oct/08 11:19 AM

chorazin allen added a comment - 06/Nov/08 08:19 AM
The recent announcement about openspace resource consumption and the need to regulate scripts loading for both Openspaces and Homesteads underscores once again the need for scripts to be able to stop and resume cleanly without loss of state to reduce sim load. All the while that this issue is unresolved this is impossible to do in a 100% clean manner

gearsawe stonecutter added a comment - 29/Nov/08 05:13 PM - edited
Added link to this issue which was the original form many years ago before jira. Not looking like a top priority. Not only is a script reset on sim reset but also inventory store or a sim crossing.

Cinco Pizzicato added a comment - 17/Jan/09 02:36 PM - edited
I'm voting for this because of chorazin's point #2: Scripts should behave predictably. Either scripts retain their data or they don't. Which is it?

But to address another point: A data storage script that's waiting around for a linked message query is not wasting any resources, if all it's doing is waiting for a linked message. Even if it's just doing a listen to a known central server object, it will only hear that object, and the efficiency problem is handed to LL's listen filter code.

Say we have a script that turns other scripts on and off depending on when it wants them. That script is wasting resources, because it has to process the requests and do the switching on and off, all to accomplish something that could be accomplished by simply sending a linked message and waiting for a response. Managing the run-state of scripts is a waste when such management is really unnecessary, especially when multiplied across many in-world instances.

So to solve the script count problem, you add to the script load problem by requiring extra processing per data request. Assuming, of course, that LSL doesn't move as quickly as the server under which it runs.

Edit update: I just made a script that stops itself on touch. It seems to require a full prim update from the server to stop itself. Thus, if you're stopping and starting scripts, you are lag.


chorazin allen added a comment - 18/Jan/09 12:52 AM - edited
Reflecting back to my comment in November, the recent main blog announcements for Openspace/Homesteads and the release announcements for 1.25 server both confirm that the Lab is starting to take a serious look at script loading including plans to introduce some sort of script limiting/ceiling for low-use-intended regions.

That's the stick. The carrot would be fixing this issue (and others like it) that make it currently impossible for content creators to write region-friendly content which scales itself up and down depending how much it needs to do at the time. I already have code in some of my products to implement a standby mode with waking up on a touch or a collision, but I also have to have code stil running which is checking for a region restart during standby so that instead of coming out of standby I do a cold start on all the scripts in the object and then reapply the state which is global to the object having lost the state which is specific to scripts that were stopped - all that code should not be necessary; it's only there because I cannot rely on scripts to retain the state when stopped. There are also scripts I would like to stop, but cannot at all, because they hold permissions (particularly _DEBIT) which are also lost along with all the other state associated with the stopped script.

To Cinco's comment, it should go without saying that starting and stopping a script should be a very cheap operation to perform, otherwise the whole advice about monitoring TD/FPS and scaling script operation to suit is flawed.


DoctorEigen Flow added a comment - 29/Mar/09 06:07 PM
It is now March 29th, 2009... we are on the brink of nuclear war, the world is being swallowed by a recession, nature is starting to rebel violently,... and Linden is charging us more money in tier every year, than it costs to buy the 'Adobe Creative Suite' , and that's for a limited 1/4 sim?!

But they still will NOT fix issues flagged as MAJOR BUGS?!

Soon I'd imagine, they will charge us L$10 to comment here.


EddyFragment Robonaught added a comment - 07/Apr/09 08:57 PM
Whoa! Simple issue, lots of words.

Is there a problem or not?

I am writing a collection of scripts that work together,some of them are for memory of lists and only need to run under certain instances. If they are deactivated via llSetScriptState and during a restart they lose all their lists the whole project is dead. The whole point of this function as I see it is to reduce the need for quiet scripts to be running for hours or even days before they are called to operate. This is why I am writing in the llSetScriptState commands. Now I read a load of conflicting blah about it not working in this that or the other case. Would a knowlegeable Linden please put this to rest with "It is fixed" , "It isn't fixed" , "There is nothing to fix" or some other consise and accurate statement. I need to know ASAP if I should leave all my listens running to avoid list corruption or loss or if I can safely activate those scripts in question as and only when they are needed. Considering the issues surrounding the running of and the quantity of scripts in SL I think this is a MASSIVELY IMPORTANT ISSUE.

I am watching this space. Thanx Lindens everywhere. I love SL.


EddyFragment Robonaught added a comment - 07/Apr/09 09:39 PM
I have turned all my llSetScriptState 's into //llSetScriptState 's and am living in hope.

chorazin allen added a comment - 08/Apr/09 12:10 AM
@Eddy: It is not fixed, and is also over a year old now.

Plain summary: start a script, suspend it with llSetScriptState. Resume it with llSetScriptState. The behaviour when you resume is indeterminate. If the region has not rebooted whilst the script was suspended the script will resume exactly where and how it was with all running data, permissions and context intact, as you would expect. If the region has rebooted the script will restart from virgin state with all variables, context, permissions etc lost and will begin running in first-run state, ie state default and the entry handler will get executed.

Given the age of this ticket, I've recently abandoned my own efforts to voluntarily reduce script load from scripts that don't need to be running and now keep all scripts running all the time because I haven't been able to make my region restart detection 100% reliable and the script processing to save and reload state in a controlled fashion around llSetScriptState calls and/or tell my object users what's going on and why their settings/permissions just vanished is way in excess of simply continuing to run the script.


EddyFragment Robonaught added a comment - 09/Apr/09 09:56 PM
Thanx chorazin but I didn't need a summary. I understand all the conflicting comments just fine. I have noted that Periapse Linden is "still" watching this issue. Could it not be considered time to say or better do something about this bug. I quote--->

Periapse Linden added a comment - 26/Sep/08 02:50 PM
Mono is now live. Http In is underway, and the load limiting it requires makes this issue salient again.

From this very page. Note the date. How about an assignee at the very least for starters?

I am new to scripting and have run into a few bugs already. I assume as I get better and use more functions I will encounter more bugs. I fully understand the complex nature of SL but surely that is the point here. If these bugs ar not delt with in good time as the world develops there will develop more bugs and they will eventually be out of control.

This bug is old and apparently still needs fixing. Why wait till it is at the bottom of a bigger pile to fix it? Please LL can someone at least show they are interested in this issue.


Servian Serevi added a comment - 14/Nov/09 07:42 PM
This bug is STILL causing problems!!!

What a great lag reducing tool this would be if it actually worked!


Lear Cale added a comment - 16/Nov/09 05:48 AM
Please fix this issue.

For every MLPV2 menu-furniture inworld, two scripts now must stay running that would otherwise be shut off due to this behavior. MLPV2 sets many of its scripts to not-running when it's stopped (when no pose is selected). However, two of the scripts that could be set not-running have to remain running due to this behavior.

LL should do whatever possible to encourage shutting off unneeded scripts. This would reduce CPU time (due to the time spent visiting dormant scripts), and could also reduce memory usage (if state of "off" scripts were saved to disk).