In a medium saucepan, whisk together the sugar, flour and cocoa.
Add the milk and cook over medium heat, whisking constantly, until the mixture comes to a boil and has thickened to a pudding-like consistency, about 3 to 6 minutes.
Remove from the heat and transfer the mixture to the bowl of a stand mixer fitted with the beater attachment. Beat at medium-high speed for about 10 to 15 minutes, until it's below 80°F.
Reduce the speed to low and, with the mixer running, add the butter a few tablespoons at a time. Scrape down the sides of the bowl as needed, to make sure the butter is thoroughly incorporated.
Once all the butter has been mixed in, add the vanilla.
Increase the mixer speed to high. Beat the frosting for 4 to 6 minutes, until it’s light and fluffy.
If the frosting feels dense, curdled, or greasy, it’s too cold. Gently warm the mixture by setting the bowl over a pan of steaming-hot water for a few minutes (just until you see the edges begin to soften/melt), then re-whip until smooth. If the frosting feels soupy or loose, it’s too warm. Chill for 15 to 20 minutes in the refrigerator before re-whipping.