这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@return42
Copy link
Member

@return42 return42 commented Jul 8, 2025

The issue was introduced in commit: edfbf1e

Problematic code:

    def timeout_func(timeout, func, *args, **kwargs):
        ...
        if not p.is_alive():
            ret_val = que.get()
        else:
            logger.debug("terminate function after timeout is exceeded")  # type: ignore
            p.terminate()
        p.join()
        p.close()

The logger function in the else path is not defined. Was accidentally removed in commit edfbf1e without providing an appropriate replacement.

File "/usr/local/searxng/searx/plugins/calculator.py", line 216, in timeout_func
  logger.debug("terminate function after timeout is exceeded")  # type: ignore
  ^^^^^^
NameError: name 'logger' is not defined

The exception triggered by this prevents the p.terminate() from being executed. As a result, the processes accumulate in memory (memory leak).

Related:

The issue was introduced in commit: edfbf1e

Problematic code::

    def timeout_func(timeout, func, *args, **kwargs):
        ...
        if not p.is_alive():
            ret_val = que.get()
        else:
            logger.debug("terminate function after timeout is exceeded")  # type: ignore
            p.terminate()
        p.join()
        p.close()

The `logger` function in the `else` path is not defined.  Was accidentally
removed in commit edfbf1e without providing an appropriate replacement.::

    File "/usr/local/searxng/searx/plugins/calculator.py", line 216, in timeout_func
      logger.debug("terminate function after timeout is exceeded")  # type: ignore
      ^^^^^^
    NameError: name 'logger' is not defined

The exception triggered by this prevents the `p.terminate()` from being
executed. As a result, the processes accumulate in memory (memory leak).

Related: searxng/searx-instances#708 (reply in thread)
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@vojkovic
Copy link
Member

vojkovic commented Jul 8, 2025

Nicely done, will test asap

@Bnyro
Copy link
Member

Bnyro commented Jul 8, 2025

related: #4938

@return42 return42 merged commit fe52290 into searxng:master Jul 8, 2025
7 checks passed
@return42 return42 deleted the fix-calc-plg branch July 8, 2025 07:30
@inetol
Copy link
Member

inetol commented Jul 8, 2025

Why do we have so many type overrides anyway?

@return42
Copy link
Member Author

return42 commented Jul 8, 2025

Why do we have so many type overrides anyway?

Because we (e.g. in the engines) are doing a lot of monkey patching .. because we have a lot of old code that doesn't know typing .. we are in the process of gradually improving this; here are two examples.

As the PRs show, typing is a huge task .. often, entire parts of a existing model have to be rethought /re-implemented .. it will take a very long time before we can remove most of the type overrides... but there will always be a residue of overwrites... we shouldn't forget: Python is and remains a dynamically typed language. :-)

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.

Undefined logger in calculator.py

4 participants