GSM modem hang issue

I'm monitoring the modem for new sms messages about once per second. I am doing this with debugging active so I can see all of the modem activity in my serial interface. At some point my code hangs and it always seems the modem fails to return the OK after the AT+CMGL="REC UNREAD" command. The code runs for several days before it encounters this phenomena.

Has anyone a suggestion for trapping this event and recovering control?

As a follow up for those watching this topic I took some actions on my own which some may find useful. I modified the SMS.h and SMS.cpp files in the GSM library some time ago. I wanted to be able to purge all of the stored sms messages from my modem so I added GSM_SMS.flushAll() function. While digging around in the library I noticed there was another function GSM_SMS.ready() that returns an integer based on readiness of the modem. I decided to include it as a check before calling GSM_SMS.available() or any of the functions directly related to sending sms texts.

It's still too early to tell but I'm hopeful that this will help.

Just a quick addition to my notes here in case anyone else is experiencing hang issues with their program. I tried the previous method and still experienced the hang when trying to check messages. So ultimately I solved the problem by using the Watchdog timer function found on Github called Adafruit_Sleepy_Dog. It has all the necessary library elements to implement a maximum 16sec watchdog timeout and initiate a software reset of the processor. All that was necessary was to place markers on my SD card so the device will resume operation where it left off.
If interested the link to Github for this is: GitHub - adafruit/Adafruit_SleepyDog: Arduino library to use the watchdog timer for system reset and low power sleep.