Don’t know your age. Profile limits anyone from seeing your info or prior posts. So not helpful there.
Is this during sex during masturbating?
I answered this or similar here before. Just not sure where.
Stress and being in your own head is usually the culprit.
But health issues and or medications can also affect it.
Sometimes lots of hard jerking off can make real sex later not stimulating enough physically due to desensitizing.
Cock rings can help
So can a mental connection. Or stimulation other places with less focus on staying hard.