Good question, in the non-password case there is one round trip less in the UDP connection. PC sends UDP packet to ESP with update info, ESP returns OK via UDP, then they switch to a TCP connection and the update starts. In the other case it does Update Info → Challenge info → Challenge response → OK → TCP update.
In any case, you do see that UDP “OK” packet in Wireshark from the perspective of the PC for the non-password case but not in the password case, right?
So it really just drops the first packet? But why? Is this router dependent? Does the ESP’s UDP stack have a bug that causes it to just not send it?
Can you also check that it’s purely due to sending the packet twice and not via the delays introduced by the serial code by changing it to for(int i=0; i < 2; i++) { and commending out the Serial prints in the loop?
Well that is also definitely a very good possible cause.
Still the Arduino-ESP8266 implementation could be better here and at least try to reliably send that “OK” packet. They are working with UDP here, so packet loss must be expected.
Then my best guess is that they re-introduced the bug in the later firmware versions again.
This is however as I think fix-worthy in the ESP8266 core. A little bit of reliability on that OK packet would be good (or other packets in general). Can you open an issue in Issues · esp8266/Arduino · GitHub for that? You have a pretty good case here with that router bug for the issue to be taken seriously.
I followed a thread on Fritz.box UDP packet losses in the meantime and applied a workaround they were proposing there (disable hardware packet speed-up). Voilà - the two OK packets are there.
Looks like they reintroduced some bug in FritzOS at AVM.
Stuck again, after a year. There was another Fritzbox update last night, but this time the old remedy did not work again. Even with deactivated packet speed-up the issue is remaining.
Without taking the devices apart, I can not update the code for the improved ArduinoOTA.cpp, as suggested above. So I am at a dead end…
I am still blocked with this. I found no way yet to get OTA working again and now urgently need to update my devices. These are spread all over the place in dusty corners and behind furniture, so I am craving for some fix to not have to crawl around.