This bug has been around ever since Yosemite and it's freakin' annoying!! The only way to 'solve' it is by killing off the Dock via Terminal (as Jessica briefly explained). I hope a permanent fix will come any time soon as I reported this bug many times already.