foxcpp / maddy

✉️ Composable all-in-one mail server.
https://maddy.email
GNU General Public License v3.0
5.13k stars 249 forks source link

Maddy hangs after several hours/days - potential LDAP issue #546

Closed angelnu closed 2 years ago

angelnu commented 2 years ago

Describe the bug

Since I deployed Maddy several months ago I noticed that after some time I would get no emails. Restarting Maddy solves the issues. As I have a backup server and this does not happen that frequent I have not investigated it further until today.

Since it happened this evening and I still had the logs handy I noticed that after the Maddy restart I would not see incoming emails BUT my email client did show several new emails that arrived during the night. So this makes me believe the hang only affects authenticated connections.

As I use LDAP I looked at the LDAP source code in Maddy and I think there is a likely bug: if the getConn (https://github.com/foxcpp/maddy/blob/dbf14fa08373be46a171ffa73f82e91fbdf80adf/internal/auth/ldap/ldap.go#L181) times out connecting (or any other error) the mutex would not be released.

The fix could be add Unlock calls at one of the following places (I could do a PR):

Steps to reproduce

  1. Setup maddy with LDAP
  2. disconnect LDAP server and let Maddy to try to connect
  3. Start the LDAP server again
  4. See that Maddy is still not able to accept auth connections

Log files

NA

Configuration file

Attaching LDAP settings

        auth.ldap local_authdb {
            connect_timeout 1m
            debug true
            dn_template \"cn={username},ou=users,dc=ldap,dc=mydomain,dc=com\"
            starttls off
            urls ldaps://ldap.mydomain.com:636
        }

Environment information

foxcpp commented 2 years ago

Good catch, PRs are welcome!

angelnu commented 2 years ago

I will submit a PR - do you have a preference on which of the 2 proposals you preffer?