1

Topic: "internal server error" when clicking on account

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version 1.3.2 MARIADB edition
- Deployed with downloadable installer
- Ubuntu 18.04.5 LTS
- Store mail accounts in : MySQL (mariadb)
- Web server: Nginx
- Manage mail accounts with iRedAdmin-Pro: yes
====

There seem to be a lot of variations of this error over the years, and I've tried most of the suggested solutions (when they made sense for my version).  But it continues to happen.

No errors are showing in /var/log/syslog
mlmmjadmin is running and no error occurs when the "internal server error" page opens
Running mlmmjadmin in the foreground has no effect (behavior is the same, all that you see is one GET request)

I'm out of ideas, here.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: "internal server error" when clicking on account

adipose wrote:

There seem to be a lot of variations of this error over the years

"internal server error" is a common error message but doesn't bound to any particular error, it just means the background daemon service has some problem.

Try to reproduce the error with steps below:

cd /opt/www/iredadmin/
python3 iredadmin.py

It will start a development http server on 0.0.0.0:8080 (http, not https), please access this address with your web browser and reproduce the error. Show me full console output please for troubleshooting.

3

Re: "internal server error" when clicking on account

I removed everything normal that happens before I click on the user.  Then this happens:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/web/application.py", line 280, in process
    return self.handle()
  File "/usr/local/lib/python3.6/dist-packages/web/application.py", line 271, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/local/lib/python3.6/dist-packages/web/application.py", line 514, in _delegate
    return handle_class(cls)
  File "/usr/local/lib/python3.6/dist-packages/web/application.py", line 492, in handle_class
    return tocall(*args)
  File "/opt/www/iRedAdmin-Pro-SQL-4.5/controllers/sql/user.py", line 480, in GET
    discarded_aliases=discarded_aliases,
  File "/opt/www/iRedAdmin-Pro-SQL-4.5/libs/iredbase.py", line 178, in render_template
    return jinja_env.get_template(template_name).render(kwargs)
  File "/usr/lib/python3/dist-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/opt/www/iRedAdmin-Pro-SQL-4.5/libs/../templates/default/sql/user/profile.html", line 46, in top-level template code
    {% from "macros/msg_handlers.html" import warning_info, user_msg_handler with context %}
  File "/opt/www/iRedAdmin-Pro-SQL-4.5/libs/../templates/default/layout.html", line 200, in top-level template code
    {% block main %}{% endblock %}
  File "/opt/www/iRedAdmin-Pro-SQL-4.5/libs/../templates/default/sql/user/profile.html", line 267, in block "main"
    {% for _profile in all_aliases |sort %}
  File "/usr/lib/python3/dist-packages/jinja2/filters.py", line 278, in do_sort
    return sorted(value, key=key_func, reverse=reverse)
TypeError: '<' not supported between instances of 'Storage' and 'Storage'

4 (edited by broth 2020-10-29 16:45:44)

Re: "internal server error" when clicking on account

I am getting exactly the same error on my iRedMail installation 1.3.2 using the latest version of iRedAdmin Pro

@Zhang: Do you need more informations to debug and fix the issue? I'd be happy to help.
"DEBUG=True" showed more or less the same information as from the previous post.

Thanks!

5

Re: "internal server error" when clicking on account

Just got it fixed with help from another iRedAdmin-Pro customer. Here's the patch for iRedAdmin-Pro-SQL-4.5 to fix it.

NOTE: if you're not familiar with patch, please mail us to get a patched version for upgrade (https://docs.iredmail.org/migrate.or.upgrade.iredadmin.html ).

diff --git a/libs/sqllib/user.py b/libs/sqllib/user.py
index 37c4a2e0..e1be2e1c 100644
--- a/libs/sqllib/user.py
+++ b/libs/sqllib/user.py
@@ -1872,6 +1872,7 @@ def get_assigned_aliases(mail, conn=None):
             _addr = str(r.address).lower()
             _groups.append(_addr)
 
+        _groups.sort()
         return (True, _groups)
     except Exception as e:
         return (False, repr(e))
diff --git a/libs/sqllib/utils.py b/libs/sqllib/utils.py
index d021a4f8..6f5849ad 100644
--- a/libs/sqllib/utils.py
+++ b/libs/sqllib/utils.py
@@ -267,7 +267,7 @@ def search(search_string,
         # Get email addresses of returned user accounts
         _user_emails = []
         for i in result['user']:
-            _user_emails.append(str(i.username).lower())
+            _user_emails.append(str(i['username']).lower())
         _user_emails.sort()
 
         # Get per-user alias and mail forwarding addresses
diff --git a/templates/default/sql/user/profile.html b/templates/default/sql/user/profile.html
index 3cc2ec29..88d4605f 100644
--- a/templates/default/sql/user/profile.html
+++ b/templates/default/sql/user/profile.html
@@ -264,7 +264,7 @@
                                 <h4 class="size-250 fl-space">{{ _('Member of Mail Aliases') }}</h4>
                                 <div class="checklist clear">
                                     <fieldset>
-                                        {% for _profile in all_aliases |sort %}
+                                        {% for _profile in all_aliases %}
                                             {% set _name = _profile.name |e %}
                                             {% set _mail = _profile.address |e %}
 
@@ -278,7 +278,7 @@
                                         {% endfor %}
 
                                         {# Display assigned aliases which is not in same domain as current user #}
-                                        {% for _mail in assigned_aliases |sort %}
+                                        {% for _mail in assigned_aliases %}
                                             {% if not _mail.endswith('@' + cur_domain) %}
                                             <div class="checklist-item">
                                                 <span class="fl-space">
@@ -437,7 +437,7 @@
                                           rows="6"
                                           style="width: 50%"
                                           class="textarea"
-                                          >{%- for addr in user_alias_addresses |sort %}{{ addr |e }}
+                                          >{%- for addr in user_alias_addresses %}{{ addr |e }}
 {% endfor -%}
                                 </textarea>
                             </div>

6

Re: "internal server error" when clicking on account

@Zhang: Looks good, I implemented the patch and no more server errors. Great job! THANKS! ^_^

7

Re: "internal server error" when clicking on account

Thanks for the quick fix, it's working!

Is there any way this kind of error can be trapped and displayed (for admin only, if you prefer) in the browser?  Luckily it's easy to reproduce, but not all errors are.

8

Re: "internal server error" when clicking on account

adipose wrote:

Is there any way this kind of error can be trapped and displayed (for admin only, if you prefer) in the browser?

Not a good idea to display such programming error on web UI. It may leak sensitive info.

9

Re: "internal server error" when clicking on account

ZhangHuangbin wrote:
adipose wrote:

Is there any way this kind of error can be trapped and displayed (for admin only, if you prefer) in the browser?

Not a good idea to display such programming error on web UI. It may leak sensitive info.

OK--although if the user is admin wouldn't they have access to that info anyway?

Barring that, you could send such errors to some other log.  I don't understand why those errors weren't logged somewhere if they print to stderr when running in the foreground.

10

Re: "internal server error" when clicking on account

adipose wrote:

Barring that, you could send such errors to some other log.  I don't understand why those errors weren't logged somewhere if they print to stderr when running in the foreground.

Well, i think this is a programming design.

Some errors should be logged and present on the web, but some shouldn't.
Programming errors usually contains sensitive info, they should be logged (for easier troubleshooting later), but not present on the web (to prevent leaking sensitive info) -- no matter the logged account is an admin or end user.

For some programming errors, we may handle the error peacefully and return a pre-defined / default value instead of raising error and let it crash.

11

Re: "internal server error" when clicking on account

ZhangHuangbin wrote:
adipose wrote:

Barring that, you could send such errors to some other log.  I don't understand why those errors weren't logged somewhere if they print to stderr when running in the foreground.

Well, i think this is a programming design.

Some errors should be logged and present on the web, but some shouldn't.
Programming errors usually contains sensitive info, they should be logged (for easier troubleshooting later), but not present on the web (to prevent leaking sensitive info) -- no matter the logged account is an admin or end user.

For some programming errors, we may handle the error peacefully and return a pre-defined / default value instead of raising error and let it crash.

Sure, I understand that, but this error wasn't even logged, right?  What's the reason it couldn't be logged?

"Internal Server Error" is unhelpful for users and admins alike, but if the admin knew the error details would be logged to a specific place, they could go check it.  Running in the foreground is ok, but as I said, it only works if you know how to reproduce the error.