Data Session Locking

I know to save JobId for session locking, so my question is do I need to save time the data was sessionlocked? i.e SessionLockTime = os.time() / os.clock().

If so why do I need to save time, and how do I save it and use it?

One problem with saving the JobId is actors because actors run on a separate VM it will be a little like there on a separate server but with the same JobId so instead of the JobId a better option is to use GenerateGUID this will prevent actors from bypassing the lock


the reason we save the time is because we can not guaranty that a session will be unlocked

lets assume you lock a session and lets assume the server crashed or Robloxs datastore server goes down the session will stay locked forever

so this does not happen we add a timeout and we say that if a session was locked and this lock was not updated in so much time we assume that the session is dead and we bypass the lock

this is why we need to know how long ago the session was locked

os.time() uses the servers operating systems time while Roblox does a good job at keeping all the server os.time() in sync this is not 100% guaranteed

the way its done by Suphi's DataStore Module is that it uses the memorystores expiration time this guarantees all the servers see the session unlock at the exact same time

2 Likes

How long would the timeout requirement be in order for the session-lock bypass? 2 Minutes, 5? (Also take into consideration player’s who server hop in a quick span of time)

You close the session when a player exits the server so you don’t relay on the timeout you only use the timeout if the server crashes etc…

Profileservice has a timeout of 30 minutes
SuphisDatastoreModule has a default timeout of 5 minutes

Alright so let’s say I save the os.time(), when do I do the timeout checking? Is it when the player joins i.e


--Player Joins
(Data.SessionLockTime - os.time()) >= 1600s
  --Unlock session

you check when you try to open the session

if the timer has timed out you bypass the lock and lock the session to yourself even if its locked to something else

Thank you for your help, I appreciate it.

I got a question about the lock, let’s say

Player 1 Joins (Session lock applies)
Player 1 stays in server for more than 30 minutes
Player 1 leaves the server
Player 1 joins a new server, (new server checks if they’re in session lock and notices the os.time is greater than 30 minutes)
Player 1 bypasses the lock

Wouldn’t this be a problem because, let’s say the server they just left is still saving their data, but because their session lock time reached 30 minutes the new server bypassed the lock, hence overwriting the data that’s still in saving in the other server.

Correct me if I’m wrong.

Player enters server 1
Server 1 opens session and sets timeout
Server 1 waits some time for example 30 seconds then saves the cached data and updates the timeout
Server 1 waits 30 seconds again saves cached data and updates the timeout
Once player 1 exits server 1 saves cached data and removes the session lock
Then player enters server 2 and server 2 opens the session

So you keep extending the timeout everytime you save the players data so that it never times out the only time it should timeout is if the server crashes etc…

Profileservice updates the timeout every 30 seconds
Suphisdatastoremodule updates the timeout every 60 seconds

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.