In a Dremel or cordless drill, use a type-443 carbon steel brush on the interior of the barrel. Make certain to get into the side slots for the bayonet as you’re doing it.
Then, using a pencil/punch/screwdriver or other rod to fully depress the spring from inside the barrel, use a type-428 brush on the underside of the socket by going all around the protruding pin.
When you release the pencil, you’ll see that the now-shiny pin slides into the barrel to make better contact, and the interior of the barrel will make good contact with the bulb.
Similar results could probably be achieved with sandpaper/burnishing sticks. I would expect this to solve 90% of problems but not all. I’ve found this does not work as reliably on pop bumper sockets (bayonet).
You can find these on the shelf at ACE or more affordable knockoffs online.
Edit: if these are backbox-style sockets that have a protruding spring instead of a pin, YMMV. I’ve had good enough results.