Sounds like it is clearly either hanging/timing out, there is a script error somewhere – or – and we have discovered this to be a problem on some sites – another process is adding items to the html request and return values making them unreadable by the SP upgrade script. A typical example of that would be a security plugin adding tokens for example.
The first thing to do would probably be to look in the php error log to see if anything is recorded that might suggest a hang or time-out. I will also look at the instructions between 5.2.6 and 5.4.1 to see if anything stands out as potentially problematic although that is quite a big version jump…