Serious issue of ADB auto exiting ADB always exits by itself causing (many times) almost wiping my data folder on PC instead of /data on Android.

It does this even while I'm typing commands (!) as if there is a timer that makes it exit after some time.

How to prevent this from happening?

Device details: Galaxy S2 with newest cyanogenmod nightly (based on Android 4.4.4); the clockworkmod version is 6.0.5.0 or 6.0.4.8 (If I flash Dorimanx Kernel 10.43v113)

PC details Lubuntu 14.04/14.10 amd64 version with Linux 3.16-rc3
I don't know if this is the reason for you, but I've seen the symptoms you describe caused by USB problems. There are two particular possible problems:

The cable is loose, probably at the device end. Then wiggling it slightly can cause a brief disconnection. You wouldn't normally notice this, because it only lasts for a second, but it'll terminate an adb shell session, or if you're deploying an app onto the device when it happens, it'll interrupt the transfer.

There's congestion on the USB bus. This can happen when several devices (whether that's several Android devices, or one Android device and something else such as a USB stick or webcam) are connected to the same hub. ADB is not very resilient to bus congestion, so it can disconnect while you're doing a high-bandwidth operation, such as taking a screenshot or running an adb shell command with lots of output.
Sometimes this can cause a brief disconnection, but sometimes the protocol gets into a bad state, and you can only recover by physically unplugging the device and plugging it back in again.


In either case, you can tell that this is happening because, even if the disconnection is momentary, the device shows the USB debugging notification again as if it had been fully unplugged.