E-Series resetting after publish

Hello—I’m seeing some unpredictable behavior with my E-Series when it’s in its publication sequence and I’m hoping someone may have some insight. The use case is that my sensor collects data for some time while out of cellular range and then when it comes back into range, it transmits an encoded version of the whole data file line-by-line in < 622 byte chunks. I’m using @rickkas7’s SPIFFS library though I think that’s unrelated to the problem (so sorry to bug you, @rickkas7!).

What I want to see (and sometimes do see) when I get a connection, is the continued looping through my file as it publishes line-by-line until there are no data left, then it goes to sleep.

However, sometimes what I see is it publishes only one line of data (confirmed in both the Console as well as in the endpoint to a webhook) after printing its publish_id to screen and then doesn’t print anything else to screen. It then does nothing that I can observe for ~ 10 seconds (it’s configured to publish roughly once per second) then resets, starting again at the very top of my script instead of staying within the loop where it should be for a couple minutes.

Here is the most relevant code chunk, I believe:

      // print out publish ID to screen
      Serial.println(publish_id);

      // publish data
#if USING_CELL_NETWORK_UPLOAD
      // I think a good idea is to use the MAC address of the device + date/time (filename)
      // if the publish is a success....
      // Serial.println("trying to publish...");
      if (Particle.publish(publish_id, data_to_publish, 60, PRIVATE))
#endif
        {

          Serial.println("Publish Success");

          // increment upload number
          upload_num++;
          // truncate the file
          bin_file.truncate(bin_file.length() - num_of_bytes_to_encode);
          bin_file.flush();

          // reset "no upload" timeout timer
          time_of_init_state_exit_ms = millis();
        }

#if USING_CELL_NETWORK_UPLOAD
        // if the publish wasn't successful
        else
        {
          // basically, don't truncate the last bit of the file so it will retry.
          // reset "no upload" timeout timer
          time_of_init_state_exit_ms = millis();
        }

        // keep connection alive (do once every 20 seconds or more often)
        Particle.process();
#endif

        // Debugging info about file length.
        Serial.println("File Length = " + String(bin_file.length()));

In my setup() loop, I have Serial.println("Reset Reason: " + String(System.resetReason())); so I can see that every time this happens and it wakes back up, it prints “Reset Reason: 0” but that’s not very descriptive based on the resetReason list that I’ve seen.

I have those #if blocks in there so that I can change the USING_CELL_NETWORK_UPLOAD define to zero to test everything else in my code without burning through a ton of data. Are those potentially problematic in the way they’re used here (I have a couple thousand lines of code so thought I should copy in only this snippet)? I wanted to copy enough to show that I have closed if and else blocks within the USING_CELL_NETWORK_UPLOAD scenario.

Some potentially relevant specs from the Console when I am seeing this bad behavior are:
88% battery charge
Good cellular signal
0 disconnect events
2579ms round-trip time
0 rate-limited publishes
31kB of 109kB RAM used

Anyone spot anything obviously wrong or poorly done here? Thank you!