The factories in Russia and China didn't have capitalist masters. Instead the communist party leadership were the masters. Socialism doesn't eliminate masters. It just appoints them.
If state owns means of production & dictates workers the way capitalists do, then that is state capitalism & not communism. Also Socialism is political ideology, not economic system.