Repository: Mailu/Mailu

Issue:
mailu front fails with KeyError: 'LD_PRELOAD'
<!--

Thank you for opening an issue with Mailu. Please understand that issues are meant for bugs and enhancement-requests.
For **user-support questions**, reach out to us  on [matrix](https://matrix.to/#/#mailu:tedomum.net).

To be able to help you best, we need some more information.

Before you open your issue
- Check if no issue or pull-request for this already exists.
- Check [documentation](https://mailu.io/master/) and [FAQ](https://mailu.io/master/faq.html). (Tip, use the search function on the documentation page)
- You understand `Mailu` is made by volunteers in their **free time** — be concise, civil and accept that delays can occur.
- The title of the issue should be short and simple. It should contain specific terms related to the actual issue. Be specific while writing the title.

Please put your text outside of the comment blocks to be visible. You can use the button "Preview" above to check.

-->

## Environment & Version

### Environment

- [X] docker compose
- [ ] kubernetes
- [ ] docker swarm

### Version

- Version: `2.0`

<!--
To find your version, get the image name of a mailu container and read  the version from the tag (example for version 1.7).

$> docker ps -a | grep mailu
140b09d4b09c    mailu/roundcube:1.7    "docker-php-entrypoi…"    2 weeks ago    Up 2 days (healthy)    80/tcp
$> grep MAILU_VERSION docker-compose.yml mailu.env
-->

## Description
<!--
Further explain the bug in a few words. It should be clear what the unexpected behaviour is.  Share it in an easy-to-understand language.
-->
Pulled the image today to create a new server. The nginx fails with the following error.

## Replication Steps
<!--
Steps for replicating your issue
-->
* docker-compose up -d
* docker shows unhealthy front container
* docker logs mailu_front_1

## Observed behaviour
<!--
Explain or paste the result you received.
-->

## Expected behaviour
<!--
Explain what results you expected - be as specific as possible.
Just saying "it doesn’t work as expected" is not useful. It's also helpful to describe what you actually experienced.
-->

## Logs
<!--
Often it is very useful to include log fragments of the involved component.
You can get the logs via `docker logs <container name> --tail 1000`.
For example for the admin container: `docker logs mailu_admin_1 --tail 1000`
or using docker compose `docker compose -f /mailu/docker-compose.yml logs --tail 1000 admin`

If you can find the relevant section, please share only the parts that seem relevant. If you have any logs, please enclose them in code tags, like so:

-->


```
# docker logs mailu_front_1
Traceback (most recent call last):
  File "/config.py", line 8, in <module>
    args = system.set_env()
  File "/app/venv/lib/python3.10/site-packages/socrate/system.py", line 80, in set_env
    del os.environ['LD_PRELOAD']
  File "/usr/lib/python3.10/os.py", line 696, in __delitem__
    raise KeyError(key) from None
KeyError: 'LD_PRELOAD'
```



Discussion:
Seems like the env `"LD_PRELOAD=/usr/lib/libhardened_malloc.so" `is set when I run docker inspect
Can't reproduce it here with 2.0.8.

Which specific version of Mailu are you running? ``cat /version`` from a container
What CPU are you running it from? ``cat /proc/cpuinfo``
Did you set LD_PRELOAD manually in mailu.env?
Same here with both `ghcr.io/mailu/nginx:2.0.7` and `ghcr.io/mailu/nginx:2.0.8`.

I reverted to `2.0.6` where the error does not occur.
@RandomByte same questions.

The code is here: https://github.com/Mailu/Mailu/blob/master/core/base/libs/socrate/socrate/system.py#L80 and yes it's new. LD_PRELOAD is set https://github.com/Mailu/Mailu/blob/master/core/base/Dockerfile#L83 and should always be present: there should be no problem removing it.
OK, found the problem; I'm working on a fix

Resolving patch:
diff --git a/core/base/libs/socrate/socrate/system.py b/core/base/libs/socrate/socrate/system.py
--- a/core/base/libs/socrate/socrate/system.py
+++ b/core/base/libs/socrate/socrate/system.py
@@ -68,6 +68,9 @@ def _is_compatible_with_hardened_malloc():
             # See #2764, we need vmovdqu
             if line.startswith('flags') and ' avx ' not in line:
                 return False
+            # See #2541
+            if line.startswith('Features') and ' lrcpc ' not in line:
+                return False
     return True
 
 def set_env(required_secrets=[], log_filters=[], log_file=None):
@@ -76,7 +79,8 @@ def set_env(required_secrets=[], log_filters=[], log_file=None):
         sys.stderr = LogFilter(sys.stderr, log_filters, log_file)
     log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", 'WARNING'))
 
-    if not _is_compatible_with_hardened_malloc():
+    if 'LD_PRELOAD' in os.environ and not _is_compatible_with_hardened_malloc():
+        log.warning('Disabling hardened-malloc on this CPU')
         del os.environ['LD_PRELOAD']
 
     """ This will set all the environment variables and retains only the secrets we need """


Test patch: