Client.read causes infinite loop.

I have the following piece of code and every so often normally about 10-15 minutes of running my arduino gets stuck in an infinite loop.

while ( true  ) {
      Serial.println(sensorNum2);
          if (alarm_client.connected()) {
              Serial.println("I'm finding alarm values yo");
              sensorNum2 = alarm_client.read();
              alarm_client.read();          
           }
           
           if ( ((sensorNum2 < 57) && (sensorNum2 > 48)) ) {
              
              for(int j = 0; j < sensorNum2; j++) {
                 AlarmTemps[j] = ((alarm_client.read() - '0') * 10) + ((alarm_client.read() - '0'));
                 alarm_client.read();
                 AlarmTemps[j] = AlarmTemps[j] + ((alarm_client.read() - '0') * 0.1) + ((alarm_client.read() - '0') * 0.01);
                 alarm_client.read();
              }
                  
             break;
           }
           
      }

every so often … my arduino gets stuck in an infinite loop.

The first line of code shown IS an infinite loop.

Snippets-are-us is down the road a piece. This is All-The-Code-All-The-Time. You know what to do.

I solved the problem, turns out it would fail to connect and then continue reading the failed connection. All I had to do was add an else statement that would reconnect.