USB:

 - If this happens using USB, use a different USB cable, it's the number one culprit


WiFi:

 - Make sure battery optimization is tuned off for: Android Auto and WiFi Launcher

 - Check that phone Bluetooth doesn't get disconnected, that will trigger WiFi disconnection as well

 - If you have the possibility try changing between 2.4Ghz and 5Ghz.

 - Observe if disconnection happens in same spot, it can be caused by interference, which is more common then expected.