@@ -66,15 +66,29 @@ export const SESSION_LOCK_CONSTANTS = {
6666 * @returns true if any instance is currently active
6767 */
6868export function checkSessionLockFree ( ) : boolean {
69+ const prefixedLogger = logger . getChild ( `checkSessionLockFree` ) ;
70+
6971 const lastPingTime = window . localStorage . getItem ( SESSION_LOCK_CONSTANTS . STORAGE_ITEM_PING ) ;
7072 if ( lastPingTime === null ) {
7173 // no other holder
74+ prefixedLogger . info ( "No other session has the lock" ) ;
7275 return true ;
7376 }
7477
78+ const lockHolder = window . localStorage . getItem ( SESSION_LOCK_CONSTANTS . STORAGE_ITEM_OWNER ) ;
79+
7580 // see if it has expired
7681 const timeAgo = Date . now ( ) - parseInt ( lastPingTime ) ;
77- return timeAgo > SESSION_LOCK_CONSTANTS . LOCK_EXPIRY_TIME_MS ;
82+
83+ const remaining = SESSION_LOCK_CONSTANTS . LOCK_EXPIRY_TIME_MS - timeAgo ;
84+ if ( remaining <= 0 ) {
85+ // another session claimed the lock, but it is stale.
86+ prefixedLogger . info ( `Last ping (from ${ lockHolder } ) was ${ timeAgo } ms ago: lock is free` ) ;
87+ return true ;
88+ }
89+
90+ prefixedLogger . info ( `Last ping (from ${ lockHolder } ) was ${ timeAgo } ms ago: lock is taken` ) ;
91+ return false ;
7892}
7993
8094/**
@@ -95,7 +109,7 @@ export async function getSessionLock(onNewInstance: () => Promise<void>): Promis
95109 /** unique ID for this session */
96110 const sessionIdentifier = uuidv4 ( ) ;
97111
98- const prefixedLogger = logger . withPrefix ( `getSessionLock[${ sessionIdentifier } ]` ) ;
112+ const prefixedLogger = logger . getChild ( `getSessionLock[${ sessionIdentifier } ]` ) ;
99113
100114 /** The ID of our regular task to service the lock.
101115 *
@@ -133,7 +147,7 @@ export async function getSessionLock(onNewInstance: () => Promise<void>): Promis
133147 return 0 ;
134148 }
135149
136- prefixedLogger . info ( `Last ping (from ${ lockHolder } ) was ${ timeAgo } ms ago, waiting` ) ;
150+ prefixedLogger . info ( `Last ping (from ${ lockHolder } ) was ${ timeAgo } ms ago, waiting ${ remaining } ms ` ) ;
137151 return remaining ;
138152 }
139153
0 commit comments