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

ensure that storm httpapis tear down runtime tasks if the remote disconnects #1889

Merged
merged 5 commits into from
Sep 24, 2020
Merged
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
6 changes: 6 additions & 0 deletions synapse/lib/httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ async def _reqUserAllow(self, perm):

class Handler(HandlerBase, t_web.RequestHandler):

def prepare(self):
self.task = asyncio.current_task()

def on_connection_close(self):
self.task.cancel()

async def _reqValidOpts(self, opts):

if opts is None:
Expand Down
36 changes: 36 additions & 0 deletions synapse/tests/test_lib_httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,42 @@ async def test_http_storm(self):

self.eq(0x01020304, node[0][1])

# Task cancellation during long running storm queries works as intended
body = {'query': '.created | sleep 10'}
task = None
async with sess.get(f'https://localhost:{port}/api/v1/storm', json=body) as resp:

async for byts, x in resp.content.iter_chunks():

if not byts:
break

mesg = json.loads(byts)
if mesg[0] == 'node':
task = core.boss.tasks.get(list(core.boss.tasks.keys())[0])
break

self.nn(task)
self.true(await task.waitfini(6))
self.len(0, core.boss.tasks)

task = None
async with sess.get(f'https://localhost:{port}/api/v1/storm/nodes', json=body) as resp:

async for byts, x in resp.content.iter_chunks():

if not byts:
break

mesg = json.loads(byts)
self.len(2, mesg) # Is if roughly shaped like a node?
task = core.boss.tasks.get(list(core.boss.tasks.keys())[0])
break

self.nn(task)
self.true(await task.waitfini(6))
self.len(0, core.boss.tasks)

# check reqvalidstorm with various queries
tvs = (
('test:str=test', {}, 'ok'),
Expand Down