It could be a problem with the lens or with the camera. How does the lens respond when you operate the lens mechanisms with your fingers? How does the communicating pin of the camera look when you shoot it with no lens?
If you're lucky, maybe one of the pins just needs a little extra lubrication.
I had a lens that sometimes wouldn't close its aperture before the shot. But sometimes it would. I took the lens for a CLA and it seemed to temporarily fix it, but maybe that was an illusion as the problem eventually came back and the aperture eventually stuck wide open permanently. But this was a Soviet lens of lower mechanical quality.