This problem has been bugging me for ages and I can\'t seem to fix it or fully localize the source of the problem (although at times I can force it by allowing the phone to Stan
Not sure if anyone will find this answer valuable, but I had a similar situation, where my device was online, and then randomly went offline. I tried things like checking the cable, adb kill-server, and so on. What finally worked for me was restarting my computer and my phone. I feel like this will only be applicable if you find that your device is suddenly offline, when it was working fine before.