what they said.
Check the mags - it does this on all mags? how old are they and what kind of followers do they have installed? how many mags do you have? If you only have 2 mags and it used to do it every once in a while... well, maybe the second mag follower finally wore down.

Check the slide stop for wear - they are like $20, how old is the glock?
does it fail to lock back when you insert an empty mag and manually rack the slide? or only when you are shooting?
who did the trigger and mag drop swap out? It is easy to re-assemble the 3 pin clocks and put the 2 forward pins in wrong... but that usually results in the opposite - a bolt action glock.