Under stress people do stupid shit. Unless one trains to handle those situations or calm as a cucumber by default he'll do stupid shit.
One also needs a solid situational awareness to measure up all the information needed to make decisions quick and act. In a situation you described many things to keep track (from the criminals, their behaviour, possible civilians, changes in surroundings, whatever). Unless one trains his situational awareness he'll fail in all that.
It might be hard to claim self-defense if things take a legal turn. Have to check your local laws what they say about self-defense.
Criminals might be under influence of substances, and might don't care if they get a bit pepper sprayed, or that you wave a gun.
Chances are if you pull out the gun, they might provoke you to the point where you have to use it and you can't.
Police shows up in the wrong time all the time, perhaps when you're waving your gun.
Back to preparedness:
To provoke confrontations, one needs to be fit. Situation might demand to pull on the rabbit shoes and run, and you have to run fast and for a long time. Situation might demand one has to wrestle the opponents. This also needs endurance (a drawn out brawl is very tiring), and muscles, to keep punching, kicking, grappling, or holding them down.
To fight a brawl, one needs to be practiced in it. And not just how to subdue opponents, but have to stand the hits and kicks one get. Injuries can occur, pain certainly will, and has to ignore them to keep fighting.
Has to know the area, the streets, the geography. Needs exit plan.
Once things start there is no going back, and things can go sideways in nine ways to Sunday very easily.