handle reconnections and server restart gracefully