Mechanical/chemical/electrical engineers have a similar problem that 30 years experience isn't much more useful than 10, wages tend to top out early and you're vulnerable to being laid off and never hired again in your 40s/50s. One advantage over software is that the skills change perhaps less frequently but that is offset by lower overall demand.
While you're in your 20's think about what you're going to do at the end of your 20 year window. Are you moving up to management? Have extensive business knowledge to add to tech skills? Have a second career planned? Or saved enough money to retire or semi-retire? Of course you can actively stay up to date with latest technology but that is much tougher than it sounds. You need to have thought a lot about this before you hit 40.
For all the young guys out there. Don't think it wont happen to you. If you just follow day by day one day you'll wake up with a big mortgage, a couple of expensive kids, maybe a divorce and a bunch of recruiters that never return your phone calls. You need to avoid that place.