mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Merge pull request #2858 from overleaf/sk-make-lock-timeout-configurable
Make lock timeout configurable GitOrigin-RevId: c1df72a7cae56db125e090ada75b2c56ca9853bb
This commit is contained in:
@@ -6,6 +6,7 @@ const logger = require('logger-sharelatex')
|
|||||||
const os = require('os')
|
const os = require('os')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
|
const settings = require('settings-sharelatex')
|
||||||
|
|
||||||
const HOST = os.hostname()
|
const HOST = os.hostname()
|
||||||
const PID = process.pid
|
const PID = process.pid
|
||||||
@@ -14,12 +15,22 @@ let COUNT = 0
|
|||||||
|
|
||||||
const LOCK_QUEUES = new Map() // queue lock requests for each name/id so they get the lock on a first-come first-served basis
|
const LOCK_QUEUES = new Map() // queue lock requests for each name/id so they get the lock on a first-come first-served basis
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
{ lockManagerSettings: settings.lockManager },
|
||||||
|
'LockManager initialising'
|
||||||
|
)
|
||||||
|
|
||||||
const LockManager = {
|
const LockManager = {
|
||||||
LOCK_TEST_INTERVAL: 50, // 50ms between each test of the lock
|
// ms between each test of the lock
|
||||||
MAX_TEST_INTERVAL: 1000, // back off to 1s between each test of the lock
|
LOCK_TEST_INTERVAL: settings.lockManager.lockTestInterval || 50,
|
||||||
MAX_LOCK_WAIT_TIME: 10000, // 10s maximum time to spend trying to get the lock
|
// back off to ms between each test of the lock
|
||||||
REDIS_LOCK_EXPIRY: 30, // seconds. Time until lock auto expires in redis
|
MAX_TEST_INTERVAL: settings.lockManager.maxTestInterval || 1000,
|
||||||
SLOW_EXECUTION_THRESHOLD: 5000, // 5s, if execution takes longer than this then log
|
// ms maximum time to spend trying to get the lock
|
||||||
|
MAX_LOCK_WAIT_TIME: settings.lockManager.maxLockWaitTime || 10000,
|
||||||
|
// seconds. Time until lock auto expires in redis
|
||||||
|
REDIS_LOCK_EXPIRY: settings.lockManager.redisLockExpiry || 30,
|
||||||
|
// ms, if execution takes longer than this then log
|
||||||
|
SLOW_EXECUTION_THRESHOLD: settings.lockManager.slowExecutionThreshold || 5000,
|
||||||
|
|
||||||
// Use a signed lock value as described in
|
// Use a signed lock value as described in
|
||||||
// http://redis.io/topics/distlock#correct-implementation-with-a-single-instance
|
// http://redis.io/topics/distlock#correct-implementation-with-a-single-instance
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ else
|
|||||||
user: undefined
|
user: undefined
|
||||||
pass: undefined
|
pass: undefined
|
||||||
|
|
||||||
|
intFromEnv = (name, defaultValue) ->
|
||||||
|
if defaultValue in [null, undefined] or typeof defaultValue != 'number'
|
||||||
|
throw new Error("Bad default integer value for setting: #{name}, #{defaultValue}")
|
||||||
|
parseInt(process.env[name], 10) || defaultValue
|
||||||
|
|
||||||
module.exports = settings =
|
module.exports = settings =
|
||||||
|
|
||||||
allowAnonymousReadAndWriteSharing:
|
allowAnonymousReadAndWriteSharing:
|
||||||
@@ -190,6 +195,12 @@ module.exports = settings =
|
|||||||
# that are sent out, generated links, etc.
|
# that are sent out, generated links, etc.
|
||||||
siteUrl : siteUrl = process.env['PUBLIC_URL'] or 'http://localhost:3000'
|
siteUrl : siteUrl = process.env['PUBLIC_URL'] or 'http://localhost:3000'
|
||||||
|
|
||||||
|
lockManager:
|
||||||
|
lockTestInterval: intFromEnv('LOCK_MANAGER_LOCK_TEST_INTERVAL', 50)
|
||||||
|
maxTestInterval: intFromEnv('LOCK_MANAGER_MAX_TEST_INTERVAL', 1000)
|
||||||
|
maxLockWaitTime: intFromEnv('LOCK_MANAGER_MAX_LOCK_WAIT_TIME', 10000)
|
||||||
|
redisLockExpiry: intFromEnv('LOCK_MANAGER_REDIS_LOCK_EXPIRY', 30)
|
||||||
|
slowExecutionThreshold: intFromEnv('LOCK_MANAGER_SLOW_EXECUTION_THRESHOLD', 5000)
|
||||||
|
|
||||||
# Used to close the editor off to users
|
# Used to close the editor off to users
|
||||||
editorIsOpen: process.env['EDITOR_IS_OPEN'] or true
|
editorIsOpen: process.env['EDITOR_IS_OPEN'] or true
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ services:
|
|||||||
PROJECT_HISTORY_ENABLED: 'true'
|
PROJECT_HISTORY_ENABLED: 'true'
|
||||||
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
||||||
LINKED_URL_PROXY: 'http://localhost:6543'
|
LINKED_URL_PROXY: 'http://localhost:6543'
|
||||||
|
LOCK_MANAGER_MAX_LOCK_WAIT_TIME: 30000
|
||||||
NODE_ENV: test
|
NODE_ENV: test
|
||||||
SHARELATEX_CONFIG:
|
SHARELATEX_CONFIG:
|
||||||
command: npm run test:acceptance:app
|
command: npm run test:acceptance:app
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ services:
|
|||||||
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley,zotero'
|
||||||
MOCHA_GREP: ${MOCHA_GREP}
|
MOCHA_GREP: ${MOCHA_GREP}
|
||||||
NODE_ENV: test
|
NODE_ENV: test
|
||||||
|
LOCK_MANAGER_MAX_LOCK_WAIT_TIME: 30000
|
||||||
# SHARELATEX_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING: 'true'
|
# SHARELATEX_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING: 'true'
|
||||||
SHARELATEX_CONFIG:
|
SHARELATEX_CONFIG:
|
||||||
command: npm run test:acceptance:app
|
command: npm run test:acceptance:app
|
||||||
|
|||||||
@@ -38,7 +38,16 @@ describe('LockManager - getting the lock', function() {
|
|||||||
return { auth() {} }
|
return { auth() {} }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'settings-sharelatex': { redis: {} },
|
'settings-sharelatex': {
|
||||||
|
redis: {},
|
||||||
|
lockManager: {
|
||||||
|
lockTestInterval: 50,
|
||||||
|
maxTestInterval: 1000,
|
||||||
|
maxLockWaitTime: 10000,
|
||||||
|
redisLockExpiry: 30,
|
||||||
|
slowExecutionThreshold: 5000
|
||||||
|
}
|
||||||
|
},
|
||||||
'metrics-sharelatex': {
|
'metrics-sharelatex': {
|
||||||
inc() {},
|
inc() {},
|
||||||
gauge() {}
|
gauge() {}
|
||||||
|
|||||||
@@ -38,7 +38,16 @@ describe('LockManager - trying the lock', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'settings-sharelatex': { redis: {} },
|
'settings-sharelatex': {
|
||||||
|
redis: {},
|
||||||
|
lockManager: {
|
||||||
|
lockTestInterval: 50,
|
||||||
|
maxTestInterval: 1000,
|
||||||
|
maxLockWaitTime: 10000,
|
||||||
|
redisLockExpiry: 30,
|
||||||
|
slowExecutionThreshold: 5000
|
||||||
|
}
|
||||||
|
},
|
||||||
'metrics-sharelatex': {
|
'metrics-sharelatex': {
|
||||||
inc() {}
|
inc() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user