Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve scheduler loop error (SYN-7132) #4058

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changes/ff623ded36292878c995dfcf1874daf4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
desc: Fixed a scheduler loop error during a mirror promotion.
prs: []
type: bug
...
7 changes: 6 additions & 1 deletion synapse/lib/agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,12 @@ async def clearRunningStatus(self):
for appt in list(self.appts.values()):
if appt.isrunning:
logger.debug(f'Clearing the isrunning flag for {appt.iden}')
await self.core.addCronEdits(appt.iden, {'isrunning': False})
edits = {
OCBender marked this conversation as resolved.
Show resolved Hide resolved
'isrunning': False,
'lastfinishtime': self._getNowTick(),
'lasterrs': ['aborted'] + appt.lasterrs[-4:]
}
await self.core.addCronEdits(appt.iden, edits)

async def runloop(self):
'''
Expand Down
103 changes: 102 additions & 1 deletion synapse/tests/test_lib_agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def looptime():
await self.asyncraises(s_exc.DupIden, core.addCronJob(cdef))
await core.delCronJob(viewiden)

self.nn(core.getAuthGate(viewiden))
self.nn(await core.getAuthGate(viewiden))

async def test_agenda_persistence(self):
''' Test we can make/change/delete appointments and they are persisted to storage '''
Expand Down Expand Up @@ -1097,3 +1097,104 @@ async def task():
self.eq(cdef01.get('lastresult'), 'cancelled')
self.gt(cdef00['laststarttime'], 0)
self.eq(cdef00['laststarttime'], cdef01['laststarttime'])

async def test_agenda_graceful_promotion_with_running_cron(self):

async with self.getTestAha() as aha:

conf00 = {
'aha:provision': await aha.addAhaSvcProv('00.cortex')
}

async with self.getTestCore(conf=conf00) as core00:
self.false(core00.conf.get('mirror'))

q = '''
while((true)) {
$lib.log.error('I AM A ERROR LOG MESSAGE')
$lib.time.sleep(6)
}
'''
msgs = await core00.stormlist('cron.at --now $q', opts={'vars': {'q': q}})
self.stormHasNoWarnErr(msgs)

crons00 = await core00.callStorm('return($lib.cron.list())')
self.len(1, crons00)

prov01 = {'mirror': '00.cortex'}
conf01 = {
'aha:provision': await aha.addAhaSvcProv('01.cortex', provinfo=prov01),
}

async with self.getTestCore(conf=conf01) as core01:

with self.getAsyncLoggerStream('synapse.storm.log', 'I AM A ERROR LOG MESSAGE') as stream:
self.true(await stream.wait(timeout=6))

cron = await core00.callStorm('return($lib.cron.list())')
self.len(1, cron)
self.true(cron[0].get('isrunning'))

await core01.promote(graceful=True)

self.false(core00.isactive)
self.true(core01.isactive)

await core00.sync()

cron00 = await core00.callStorm('return($lib.cron.list())')
self.len(1, cron00)
self.false(cron00[0].get('isrunning'))
self.eq(cron00[0].get('lasterrs')[0], 'aborted')

cron01 = await core01.callStorm('return($lib.cron.list())')
self.len(1, cron01)
self.false(cron01[0].get('isrunning'))
self.eq(cron01[0].get('lasterrs')[0], 'aborted')

async def test_agenda_force_promotion_with_running_cron(self):

async with self.getTestAha() as aha:

conf00 = {
'aha:provision': await aha.addAhaSvcProv('00.cortex')
}

async with self.getTestCore(conf=conf00) as core00:
self.false(core00.conf.get('mirror'))

q = '''
while((true)) {
$lib.log.error('I AM A ERROR LOG MESSAGE')
$lib.time.sleep(6)
}
'''
msgs = await core00.stormlist('cron.at --now $q', opts={'vars': {'q': q}})
self.stormHasNoWarnErr(msgs)

crons00 = await core00.callStorm('return($lib.cron.list())')
self.len(1, crons00)

prov01 = {'mirror': '00.cortex'}
conf01 = {
'aha:provision': await aha.addAhaSvcProv('01.cortex', provinfo=prov01),
}

async with self.getTestCore(conf=conf01) as core01:

with self.getAsyncLoggerStream('synapse.storm.log', 'I AM A ERROR LOG MESSAGE') as stream:
self.true(await stream.wait(timeout=6))

cron = await core00.callStorm('return($lib.cron.list())')
self.len(1, cron)
self.true(cron[0].get('isrunning'))

await core01.promote(graceful=False)

self.true(core00.isactive)
self.true(core01.isactive)

cron01 = await core01.callStorm('return($lib.cron.list())')
self.len(1, cron01)
self.false(cron01[0].get('isrunning'))
self.eq(cron01[0].get('lasterrs')[0], 'aborted')
Loading