That’s one of the signs of a faulty crankshaft position sensor.
If the computer loses the signal from this sensor, the computer see’s no reason to operate the ignition and fuel systems, and the engine shuts off.
Sometimes letting the engine cool down allows the sensor to function again.
Tester