Data too large for Background process

Former Member
Former Member
The app I wrote has a background process which parses a JSON file every 30 minutes. Used to work fine, but the past couple of weeks it's been having issues. Looking at the logs, the error that pops up is:

Message: Data provided to Background.exit() is too large

The file is only 1.2Kb. That doesn't seem too large. Anything else which may be triggering this error?
  • Given the error message that you're showing, the size of the downloaded content isn't the problem. The issue is the size of the data that you're passing off to the foreground process via the Background.exit() call. The documentation for Background.exit() specifies that the limit is supposed to be ~8KB, and if that limit is exceeded an ExitDataSizeLimitException will be thrown. One thing to note is that the documentation doesn't mention overhead associated with the serialization format and whether or not that overhead counts toward the limit. I'll say it here now, there is overhead, and it counts against you. I'm pretty sure I can create a pathological sample where a relatively small amount of data would exceed the limit.

    Are you completely replacing the background data when you call Background.exit(), or are you merging old data with new? Can you provide a sample of the json data that triggers the error (feel free to PM the data to me if you don't want to post it here).

    In terms of resolving this, one possible solution is to trim unnecessary information out of the data before passing it off to Background.exit(). If this isn't possible, then you're going to have to get clever.

  • Right before you call Background.exit(), use Sys.println() to show what you are returning and post it. As Travis said, there will be some overhead involved, and that can vary based on the complexity of the data. For example, a 1.2kb response would be larger if it's a dictionary and not a single string.
  • Former Member
    Former Member
    Hey Travis, I'd like to send a private message, but this HORRIBLE forum software won't let me. I try to enable Private Messaging from my settings and save, but it never does save. Instead, the box always remains unchecked. I have used 3 different browsers.

    Any other ideas?

    To Garmin. FIX THIS FORUM!!! It is the worst forum to post I have ever experienced. The community is great, but the software makes communicating frustrating and unbearable.
  • Yeah, I'm not sure what changed recently, but the forum software is now broken more than ever. AFAICT, this just started in the last week or so. Regardless, I have doubts that it will get fixed right away. We will all have to be patient.

    Paste the code into a .TXT file, and attach that to your PM.
  • Former Member
    Former Member
    I can't even send a private message. In my account settings, I see that the option to enable private messaging is not checked. Checking and saving it produces this ajax error:

    POST https://forums.garmin.com/profile/saveAccountSettings?userid=1885048 500

    I may just have to upload it to dropbox at this point.
  • You could also just post it here. If you have trouble attaching a file, copy/paste it in a post, or you can try a code block like you did in the first post.
  • Former Member
    Former Member
    Here's a Dropbox link to the code and JSON URL: https://www.dropbox.com/s/5wcxc0sjfi...herStation.txt

    Open to ANY suggestions and optimization tips. :)

    Thanks guys!
  • In parseWeather() add

    System.println(data);

    before you do the Background.exit() and post what you see on the console. As the size of that is what's throwing the exception.

    As a tip, here's something I do in similar background services. When you get an error in receiveWeather, do a Background.exit(responseCode), and then in onBackgroundData in AppBase, check for a "Number" (with instanceof), and that way you can handle the error in the main app.
  • When you see the output from the println(), you'll likely see some things your main app doesn't need. So remove those from the data you return in Background.exit(). That could fix your problem right there.
  • Former Member
    Former Member
    I use everything in the JSON since it's a custom JSON file I built. Here's what is returned before the Background exit:

    Background: {pressure=>29.56, temp_high=>44, forecast_low=>42, sunrise=>1542899880, barometric_trend=>0, forecast_high=>48, hourly_forecast=>[{temp=>45, hour=>4, pop=>89}, {temp=>44, hour=>5, pop=>88}, {temp=>44, hour=>6, pop=>88}, {temp=>43, hour=>7, pop=>88}, {temp=>43, hour=>8, pop=>88}, {temp=>43, hour=>9, pop=>88}, {temp=>43, hour=>10, pop=>88}, {temp=>43, hour=>11, pop=>88}, {temp=>43, hour=>12, pop=>88}], condition=>6, hourly_forecast_update=>3:15pm, temp_low=>38, sunset=>1542933180, daily_forecast_update=>3:15pm, temp=>43, station_update=>3:14, pop=>99, wind_speed=>12, rain_amount=>0.58, daily_forecast=>[{date=>22, pop=>99, day=>Thu, max=>48, icon=>6, min=>42}, {date=>23, pop=>98, day=>Fri, max=>47, icon=>6, min=>38}, {date=>24, pop=>34, day=>Sat, max=>47, icon=>5, min=>37}, {date=>25, pop=>47, day=>Sun, max=>49, icon=>6, min=>40}, {date=>26, pop=>91, day=>Mon, max=>50, icon=>6, min=>44}, {date=>27, pop=>94, day=>Tue, max=>52, icon=>6, min=>43}, {date=>28, pop=>58, day=>Wed, max=>49, icon=>6, min=>40}, {date=>29, pop=>61, day=>Thu, max=>48, icon=>6, min=>42}]}