One up for the crankshaft sensor. I had same issues, engine would cut-off randomly in traffic. Initially I changed the blue relay as it was the easiest option but that proved to be a waste of money
. Eventually I replaced the crankshaft sensor and the car had been fine since. The car is a 2007 e90 320d. Pretty hard to replace though, labor was much more than the part itself.