Improved stability code that handles shutdown of the communications channel