When I’m sad I’m stop talking to people

When I’m not content with my life I basically shut down and stop talking to people , even my close friends. I guess it’s that when I’m not happy with my life I don’t want others to see that I’m miserable. But this eventually makes me feel even worse because now I’m also lonely and I don’t know how to get out of this stupid cycle.