To avoid this problem, only set an impact pistol. This isn't always possible, however. Always send multiple torps in case one of them detonates prematurely. This usually alerts the ship or convoy of a sub presence and they begin evasive maneuvers. If another torp is almost already there, you'll have a better chance of hitting since the ship can't get out of the way in time.
This gives you more time to get out of there if you're in the middle of the convoy. Speaking of that, the longer the torp has to go, the better the chance of this happening (i.e. magnetic shots from 2km away isn't a good idea)
__________________
|