If it does it with one mag, it's a mag problem. If it does it with multiple mags, either your grip is preventing the slide stop from engaging the slide or your slide stop spring isn't installed properly.
I've run across several Glocks where the owner didn't know that you must replace the locking block pin BEFORE installing the slide stop lever. Reverse that, and the slide stop lever spring gets crunched.
.