Skip to content

[Bug] Added asyncio due to virustotal_public module issue#727

Merged
adulau merged 1 commit into
MISP:mainfrom
lydionLuna:virustotal_public_module_patch
May 7, 2025
Merged

[Bug] Added asyncio due to virustotal_public module issue#727
adulau merged 1 commit into
MISP:mainfrom
lydionLuna:virustotal_public_module_patch

Conversation

@lydionLuna
Copy link
Copy Markdown
Contributor

Hi,

I've encountered the following issue when using the virustotal_public module:

  File "/home/misp-modules/.local/lib/python3.11/site-packages/misp_modules/__init__.py", line 223, in post
    response = yield tornado.gen.with_timeout(timeout, future)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/tornado/gen.py", line 766, in run
    value = future.result()
            ^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/misp_modules/__init__.py", line 210, in run_request
    response = module.handler(q=json_payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/misp_modules/modules/expansion/virustotal_public.py", line 242, in handler
    client = vt.Client(request['config']['apikey'],
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/vt/client.py", line 241, in __init__
    self._connector = aiohttp.TCPConnector(ssl=self._verify_ssl)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 776, in __init__
    super().__init__(
  File "/home/misp-modules/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 232, in __init__
    loop = get_running_loop(loop)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/misp-modules/.local/lib/python3.11/site-packages/aiohttp/helpers.py", line 300, in get_running_loop
    loop = asyncio.get_event_loop()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/asyncio/events.py", line 681, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'ThreadPoolExecutor-0_0'.

The issue seems to stem from vt.Client which runs asynchronously causing the misp virustotal_public module to fail as there is no event loop in the thread. In my current environment, I've added the following inside the virustotal_public handler as a temporary fix:

    import asyncio
    try:
        asyncio.get_running_loop()
    except RuntimeError:
        asyncio.set_event_loop(asyncio.new_event_loop())

Ref: #726

@ostefano ostefano requested a review from adulau May 6, 2025 13:26
@adulau adulau merged commit 8895737 into MISP:main May 7, 2025
2 of 6 checks passed
@adulau
Copy link
Copy Markdown
Member

adulau commented May 8, 2025

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants