[GH-ISSUE #3089] Postfix connection refused and all message been rejected issue with ad-hoc and conf solutions. #1759

Closed
opened 2026-02-27 11:18:58 +03:00 by kerem · 3 comments
Owner

Originally created by @yellowsoar on GitHub (Oct 10, 2023).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/3089

Impacted versions

  • OS Type: Debian/Ubuntu
  • OS Version: Debian GNU/Linux 11 (bullseye)
  • Database Type: PostgreSQL
  • Database version: 13.11-0+deb11u1 amd64
  • Modoboa: 2.2.0
  • installer used: Yes
  • Webserver: Nginx

Steps to reproduce

apt install certbot nginx python3-certbot-nginx git vim
certbot certonly --nginx
git clone https://github.com/modoboa/modoboa-installer
cd modoboa-installer/
python3 run.py --stop-after-configfile-check <yourdomain>
vim installer.cfg
hostnamectl set-hostname <yourdomain>
python3 run.py <yourdomain> --debug

Current behavior

  • The modoboa website is accessible but I found a lot of rejected messages in /Top navigation bar/Statistics/Mail traffic
    20231010T153637Z
  • Found the following log from the server by tail -f /var/log/mail.log
    postfix/smtpd[454316]: warning: connect to 127.0.0.1:9999: Connection refused
    postfix/smtpd[454316]: warning: problem talking to server 127.0.0.1:9999: Connection refused
    
  • Found the following log from the server by journalctl -u supervisor -f
    thanks to https://github.com/modoboa/modoboa/issues/2561 and https://serverfault.com/q/1100917
    supervisord[454998]: 2023-10-09 21:23:46,780 INFO exited: policyd (exit status 1; not expected)
    supervisord[454998]: 2023-10-09 21:23:47,784 INFO spawned: 'policyd' with pid 455089
    supervisord[454998]: 2023-10-09 21:23:48,786 INFO success: policyd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    
  • Tried to activate the policy daemon manually by /srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon and got the following error messages.
    Traceback (most recent call last):
      File "/srv/modoboa/instance/manage.py", line 22, in <module>
        main()
      File "/srv/modoboa/instance/manage.py", line 18, in main
        execute_from_command_line(sys.argv)
      File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
        utility.execute()
      File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
        self.execute(*args, **cmd_options)
      File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
        output = self.handle(*args, **options)
      File "/srv/modoboa/env/lib/python3.9/site-packages/modoboa/policyd/management/commands/policy_daemon.py", line 39, in handle
        server = loop.run_until_complete(coro)
      File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
        return future.result()
      File "/usr/lib/python3.9/asyncio/streams.py", line 94, in start_server
        return await loop.create_server(factory, host, port, **kwds)
      File "/usr/lib/python3.9/asyncio/base_events.py", line 1494, in create_server
        raise OSError(err.errno, 'error while attempting '
    OSError: [Errno 98] error while attempting to bind on address ('127.0.0.1', 9999): address already in use
    

Ad-hoc fix approach

Another fix approach

  • I checked the /etc/hosts and found the IPv6 setup
    # The following lines are desirable for IPv6 capable hosts
    ::1     localhost ip6-localhost ip6-loopback
    
  • So manually change the commands that the supervisor used to activate the policy daemon by vim /etc/supervisor/conf.d/policyd.conf from the follows
    command=/srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon
    
    to
    command=/srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon --host 127.0.0.1
    
  • Restart the supervisor
    service supervisor restart
    
  • Check the supervisor log and everything works as expected.
    journalctl -u supervisor -f
    
  • Or just changing the /etc/hosts perhaps?

Expected behavior

No error messages or rejected messages.

Video/Screenshot link (optional)

None

Question

Originally created by @yellowsoar on GitHub (Oct 10, 2023). Original GitHub issue: https://github.com/modoboa/modoboa/issues/3089 # Impacted versions * OS Type: Debian/Ubuntu * OS Version: Debian GNU/Linux 11 (bullseye) * Database Type: PostgreSQL * Database version: 13.11-0+deb11u1 amd64 * Modoboa: 2.2.0 * installer used: Yes * Webserver: Nginx # Steps to reproduce ```bash apt install certbot nginx python3-certbot-nginx git vim certbot certonly --nginx git clone https://github.com/modoboa/modoboa-installer cd modoboa-installer/ python3 run.py --stop-after-configfile-check <yourdomain> vim installer.cfg hostnamectl set-hostname <yourdomain> python3 run.py <yourdomain> --debug ``` # Current behavior - The modoboa website is accessible but I found a lot of rejected messages in /Top navigation bar/Statistics/Mail traffic ![20231010T153637Z](https://github.com/modoboa/modoboa/assets/4775704/bd26ce73-b75e-4d11-9a0b-8833f527dd32) - Found the following log from the server by `tail -f /var/log/mail.log` ``` postfix/smtpd[454316]: warning: connect to 127.0.0.1:9999: Connection refused postfix/smtpd[454316]: warning: problem talking to server 127.0.0.1:9999: Connection refused ``` - Found the following log from the server by `journalctl -u supervisor -f` thanks to https://github.com/modoboa/modoboa/issues/2561 and https://serverfault.com/q/1100917 ``` supervisord[454998]: 2023-10-09 21:23:46,780 INFO exited: policyd (exit status 1; not expected) supervisord[454998]: 2023-10-09 21:23:47,784 INFO spawned: 'policyd' with pid 455089 supervisord[454998]: 2023-10-09 21:23:48,786 INFO success: policyd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) ``` - Tried to activate the policy daemon manually by `/srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon` and got the following error messages. ``` Traceback (most recent call last): File "/srv/modoboa/instance/manage.py", line 22, in <module> main() File "/srv/modoboa/instance/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, **cmd_options) File "/srv/modoboa/env/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, **options) File "/srv/modoboa/env/lib/python3.9/site-packages/modoboa/policyd/management/commands/policy_daemon.py", line 39, in handle server = loop.run_until_complete(coro) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/usr/lib/python3.9/asyncio/streams.py", line 94, in start_server return await loop.create_server(factory, host, port, **kwds) File "/usr/lib/python3.9/asyncio/base_events.py", line 1494, in create_server raise OSError(err.errno, 'error while attempting ' OSError: [Errno 98] error while attempting to bind on address ('127.0.0.1', 9999): address already in use ``` # Ad-hoc fix approach - Modified the source code in https://github.com/modoboa/modoboa/blob/da18e4370ff834721f97aefb63f40225a0b14131/modoboa/policyd/management/commands/policy_daemon.py#L28 by `vim /srv/modoboa/env/lib/python3.9/site-packages/modoboa/policyd/management/commands/policy_daemon.py ` to ```python parser.add_argument("--host", type=str, default="127.0.0.1") ``` Thanks to https://stackoverflow.com/q/19246103/4464382 - Restart the supervisor ```bash service supervisor restart ``` - Check the supervisor log and everything works as expected. ``` journalctl -u supervisor -f ``` # Another fix approach - I checked the `/etc/hosts` and found the IPv6 setup ``` # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ``` - So manually change the commands that the supervisor used to activate the policy daemon by `vim /etc/supervisor/conf.d/policyd.conf` from the follows ``` command=/srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon ``` to ``` command=/srv/modoboa/env/bin/python /srv/modoboa/instance/manage.py policy_daemon --host 127.0.0.1 ``` - Restart the supervisor ```bash service supervisor restart ``` - Check the supervisor log and everything works as expected. ``` journalctl -u supervisor -f ``` - Or just changing the `/etc/hosts` perhaps? # Expected behavior No error messages or rejected messages. # Video/Screenshot link (optional) None # Question - I don't think this is a bug, and a better approach might be to let users set the policy daemon from `installer.cfg` that is generated by https://github.com/modoboa/modoboa-installer - If so, should I move this issue to https://github.com/modoboa/modoboa-installer?
kerem closed this issue 2026-02-27 11:18:58 +03:00
Author
Owner

@Spitfireap commented on GitHub (Oct 10, 2023):

Hi,
Thanks for the well written report.

I'm quite sure you encounter the same bug as another user on discord. Can you check that IPv6 is enabled on your server ? You can for instance run ifconfig and check that the internet interface do have an inet6 address.

If that's not the case, could you try commenting the ::1 localhost ip6-localhost ip6-loopback line. Some hosts do not enable ipv6 by default but keep this line in their hosts file, and it might introduce bogus situation as this one when using localhost (trying to bind to a nonexistent interface...).

<!-- gh-comment-id:1755812114 --> @Spitfireap commented on GitHub (Oct 10, 2023): Hi, Thanks for the well written report. I'm quite sure you encounter the same bug as another user on discord. Can you check that IPv6 is enabled on your server ? You can for instance run `ifconfig` and check that the internet interface do have an inet6 address. If that's not the case, could you try commenting the `::1 localhost ip6-localhost ip6-loopback` line. Some hosts do not enable ipv6 by default but keep this line in their hosts file, and it might introduce bogus situation as this one when using localhost (trying to bind to a nonexistent interface...).
Author
Owner

@yellowsoar commented on GitHub (Oct 11, 2023):

Ah ha! ifconfig! I miss the day without the container! LOL

👉 First, no inet6 in the ifconfig stdout.

try commenting the ::1 localhost ip6-localhost ip6-loopback line

👉 After that and then recover the supervisor config and restart the service it still works!

it might introduce bogus situation as this one when using localhost (trying to bind to a nonexistent interface...).

👉 I think the IPv6 localhost binding in the /etc/hosts is now confirmed as the problem.

⚠️ But!!!
After a few minutes, radicale goes wrong according to the log of the supervisor... ╮( ̄▽ ̄"")╭

<!-- gh-comment-id:1757899173 --> @yellowsoar commented on GitHub (Oct 11, 2023): Ah ha! `ifconfig`! I miss the day without the container! LOL 👉 First, no inet6 in the `ifconfig` stdout. > try commenting the `::1 localhost ip6-localhost ip6-loopback` line 👉 After that and then recover the supervisor config and restart the service it still works! > it might introduce bogus situation as this one when using localhost (trying to bind to a nonexistent interface...). 👉 I think the IPv6 localhost binding in the `/etc/hosts` is now confirmed as the problem. ⚠️ But!!! After a few minutes, `radicale` goes wrong according to the log of the supervisor... ╮( ̄▽ ̄"")╭
Author
Owner

@Spitfireap commented on GitHub (Oct 22, 2023):

Closing since the initial issue is solved. Feel free to open another issue about radicale

<!-- gh-comment-id:1774044787 --> @Spitfireap commented on GitHub (Oct 22, 2023): Closing since the initial issue is solved. Feel free to open another issue about radicale
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1759
No description provided.