Hi I don’t think there is a one fits all solution to this problem ! As many written reports have stated , during sex many things can affect it alcohol , mental state at the time pressure , stress the list is endless, I suffer from erectile dysfunction as a result of my diabetes but I am in my late 50s and have had poor control for years , you are young so I think as said it’s not the mechanics but probably the hard drive to the computer so to speak. There is also a case of now it’s in your head you think about it more often, a vicious circle. On a more practical note and again trying to be tactful here , have you tried not masturbating for a while and just going with the sex anything is worth a try
Good luck hope it all works out ok for you