I eventually managed to train myself to shut down such thoughts at bedtime, but if I'm particularly stressed or worried about something, even that doesn't work.
This was a really, really big issue for me a few months ago. My dad died & my GF dumped me a few weeks later. I was going through some HUGE life altering events, & the two combined were just too much for me. Too much change at once & I just couldn't handle it well. I barely slept for months for this reason because I couldn't shut things down. It was horrible.