Being taken down by a dog is no fun. Been there.
My strategy now is to dismount and keep the bike between me and the mutt. Riding in certain states with no leash laws or no enforcement, I wear rescue whistle around my neck and blow as loud as possible. Around 50% of dogs will retreat. Spray has to be readily accessible like clipped to a handlebar bag. The two times I had to spray, I felt bad but the only effect was the dog sneezing and rubbing its snout in the grass. Unless I am already moving fast, I get off the bike