Idle ssh connections can occure because of a tcp timeout somewhere on the network, a bad command that you executed, incorrect keepalive settings, and so on. In such event, may just kill your terminal and start a new one. Though, another easy option is to use the exit sequence ~+. (tilde and a period). This sequence would terminate the idle connection and allow you to reconnect from the same terminal.