Bug 1510158 (postfix_network-online.target)

Summary: race condition - postfix fails to start due to systemd dependency to network.target after reboot
Product: [Fedora] Fedora Reporter: Michal Ambroz <rebus>
Component: postfixAssignee: Jaroslav Škarvada <jskarvad>
Status: CLOSED DUPLICATE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 27CC: jskarvad, olysonek, whanlon
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-11-06 20:55:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1119787    

Description Michal Ambroz 2017-11-06 19:50:00 UTC
Description of problem:
-----------------------
After reboot postfix fails to start with following message in the syslog:
Nov 06 19:17:22 testmachine.example.com postfix[1200]: fatal: parameter inet_interfaces: no local interface found for 127.0.0.2

- The postfix systemd start-script is depending to network.target (and not network-online.target as it probably should be). 
- Due to this it gets to race condition where network-manager is just started but not finished setting-up network interfaces. 
- At this precise point it tries to resolve its $myhostname as defined in /etc/postfix/main.cf or obtained from gethostname() by default and gots 127.0.0.2
- then it tries to identify a local device which has this IP address configured, but doen't find any (it would be wrong address anyway)
- so the start of the service after reboot fails
- then the network manager finishes the network configuration so all the resolving works fine from now on so it is hard to get idea where is this 127.0.0.2 coming from 


Version-Release number of selected component (if applicable):
-------------------------------------------------------------
tested with postfix-3.2.3-1.fc26, but the situation is the same in rawhide and fc27.


How reproducible:
-----------------
Race condition during start of network-manager probably dependent on the number of network cards.
On one of my machines it was failing in 100% cases (machine with cca 10 physical interfaces), but on some different machine I believe it could be 100% success (like machine with only 1 physical network card).


Steps to Reproduce:
-------------------
0. have many network cards
1. instal postfix (dnf -y install postfix)
2. enable it to start automatically (systemctl enable postfix)
3. reboot the machine
4. check the staus after reboot (systemctl status postfix)


Additional info:
----------------
I believe the dependency should be changed from network.target to network-online.target in /usr/lib/systemd/system/postfix.service:

[Unit]
Description=Postfix Mail Transport Agent
After=syslog.target network-online.target
Conflicts=sendmail.service exim.service
....

Even if you manualy define correct $myhostname in /etc/postfix/main/cf and its correct IP resolv in /etc/hosts, the postfix service still fails to start at reboot, because at that point it would know the correct IP address, but that would not be ready on some network interface. The error in this situation would be :
Nov 06 19:17:22 testmachine.example.com postfix[1200]: fatal: parameter inet_interfaces: no local interface found for 111.222.33.44


Best regards
Michal Ambroz

Comment 1 Michal Ambroz 2017-11-06 20:55:02 UTC

*** This bug has been marked as a duplicate of bug 1116538 ***

Comment 2 Kenny G 2020-10-16 12:30:00 UTC Comment hidden (spam)
Comment 3 william hanlon 2020-10-26 18:35:10 UTC
(In reply to Ken Stailey from comment #2)
> $ cat /etc/systemd/system/postfix.service.d/local.conf 
> [Unit]
> After=network-online.target

This worked for me.