Sonar, which of course works by sound, has issues because of the speed variability you mention. However, IIRC (and in salt water) the range of an active sonar at the right frequency (lower is better for range) is on the order of 20 thousand meters. That said, a submarine can hide from sonar under a thermocline, assuming the sonar is above the thermocline.