Go to a Glock Shooting Sports Foundation match, and have one of there factory armorers check the gun. Take all of your magazines.
Did you buy the gun new? Are you sure all of the parts in the gun are stock and correct for the Glock 21? When gun does work, how many rounds in the mag? How many magazines do you have, and are they numbered so you can track the malfunctions? Where does brass fall when gun works? What is the condition of the fired brass?
From the described position of malfunction, it sounds like one of the following: Bad or incorrectly fitted extractor, too much recoil spring, underpowered ammo. All magazines allowing the accending round to sit too high, with ogive hitting the extracted round. Did this problem start from day one?
Hope some of this helps, GLV