I don't think I qualify at giving serious life advices, but I want you to know one thing, you haven't failed your son. You are doing your best, and your son knows it. The fact that you are doing everything you can to raise your son, and your son comforting you when you feel down, says to me that you love him and he loves you back. That's not failure at all. The only time you would truly fail yourself and your son, is when you stop trying.
Best wishes to you both!
I may also suggest keeping a notebook and writing it down to remind yourself what your priorities are.
I forgot where I saw this, but making a daily/weekly list of every little thing you are grateful of can also help you get out of that loop of feeling bad.