My solution was just to be around people. The mental spiral just stopped when I had company.
Also do know that the pain does end. I had just horrible feelings when my ex dumped me. I argued for hundreds of hours in my head with her, which obviously is pointless. Now, I couldn't put myself in that headspace if I tried. Your brain does move on. Just getting there is tough.