Problems in bed

My boyfriend and I have been together for two years and last year we went through a phase, for about a month, when he would get soft during sex or he couldn’t get hard at all, it made me feel really insecure but I kept it to myself bc I could see how embarrassed and distraught he’d get bc he said he didn’t know why it was happening. it stopped happening but it’s still something he’s really insecure and scared about if it happens again. Then last week he couldn’t get hard again, and yesterday we were celebrating an occasion and I wore lingerie, it was very sexy and we were taking dirty and then through the middle of it he went soft again. We tried to get him hard again, but it didn’t work so we just changed to our pajamas and didn’t say much bc he didn’t wanna talk. It makes me feel very insecure because i don’t know if im the reason but I don’t say anything bc I can see how it affects him as it is. So I don’t want to add more stress to it. And yesterday he got mad that it had happened and said he wasn’t thinking straight, but he just blocked me out and didn’t want to cuddle, which is all I needed bc I was hurt too and we ended up just not saying anything and he fell asleep, today we went to work and haven’t talked about it since then. I just wanna know if anyone else has had these problems and if there’s any advice.