>>889403Equipment malfunctions are a cost of business. Which is why RRs have maintenance inspections to try and eliminate as much of said cost as possible.
But, shit still sometimes happens. Most cars are run until their service date ends. If they break before that the mess it makes is cleaned up, the track repaired, and life continues on. The only exception is for tank cars that can break more easily, and can cause a much more expensive mess if they leak.
The fact is that 95% of the time everything that is put onto a mainline works good enough. 5% of the time something fails and an accident occurs. Sometimes the accidents are small, say a handle breaking off a boxcar making it impossible to open or a coupler breaking causing an entire train to detach and stop. Occasionally, they make a mess like say having a hopper door break on a hopper car causing thousands of pounds of dirt to spill onto the tracks, or a tank car's valves not working properly causing a rupture during filling. And sometimes, the locomotives don't work either, say due to something random failing (like a switch) or a computer glitch.