Because the USB handling of the Leonardo is slipped in as part of your sketch by the Arduino library, if your sketch is doing something evil (like getting stuck in an infinite loop, or not sleeping very often), it won't respond correctly to USB (which requires pretty much constant attention). You can test this by uploading something like BareMinimum and seeing if you still have connection problems. To upload in this situation you will normally need to hold down reset, press upload in the IDE, and then release reset just as the IDE says "Uploading...". This is because the routine that responds to upload attempts will not be running, and you need to ensure that the upload attempt happens while the bootloader is running.
Posting to this ancient thread because this just happened to me and since Google sent me here I'm assuming it will send other people here too ![]()