adiesner / GarminPlugin

Garmin Communicator Plugin for Linux
https://adiesner.github.io/GarminPlugin/
GNU General Public License v3.0
96 stars 16 forks source link

Filesize does not match header information #13

Closed igormancos closed 10 years ago

igormancos commented 10 years ago

Chrome: Version 34.0.1847.132 Garmin: Edge 200

I have try read files from device. First and second time the "onFinishReadFromDevice" was called, in console (I started Chrome in console) I have

14.05.14 11:13:25 Unable to load fitness file 2013-05-22-15-30-05.fit
14.05.14 11:13:25 Exception: FIT Decode Error. Filesize does not match header information!

for each file. But when I try to read the data for third time, the same error occure for the first three files, there are no errors for the next files. "onProgressReadFromDevice" called in infinite loop and json.progress.getPercentage() return from 1 to 100 and again at the 0 to 100. The "getReadCompletionState()" return each time 1 (working) state.

I think the infinite loop issue is not in this error, but maybe it help you.

igormancos commented 10 years ago

I detect when the infinite loop started. In the browser console I have "Enabling TCX compatibility mode, fitness data conversion may be lossy" 131 times (number of files from device). I close and open browser, start read data from the device. First time is ok. If I wait this 131 logs and refresh the page, the infinite loop started. When I refresh the page before 131 logs (i.e when is 129), after refresh, is ok (no infinite loop and again 131 logs)

igormancos commented 10 years ago
14.05.14 14:01:03 Creation of findDevices thread failed!
14.05.14 14:01:04 Creation of thread failed!
14.05.14 14:01:05 Creation of thread failed!

This errors started infinite loop. I have (the "rides" array containts 131 ids of files from device)

ImageController = new Garmin.DeviceControl()
ImageController.register = new ImageLoader()
ImageController.validatePlugin()
ImageController.unlock = unlockKeyPair
ImageController.findDevices()

and

this.ImageLoader = Class.create();

ImageLoader.prototype = {
  initialize: function() {},
  onFinishReadFromDevice: function(json) {
    var data = json.controller.gpsDataString;
    jQuery.post(ridePathRoute, { file: data }, function(r) {
      if (rides.length) {
        json.controller.readDetailFromDevice(fileType, rides.pop());
      }
    });
  },
  onFinishFindDevices: function(json) {
    if (rides.length) {
      rides.reverse();
      window.setTimeout((function() {
        json.controller.readDetailFromDevice(fileType, rides.pop());
      }), 500);
    }
  }
};

I read the details of 131 rides from device. Any time the read process failed with error above and I need close and open browser for work again.

adiesner commented 10 years ago

I will need to investigate this a little bit further. If you are able to provide a complete html site as example that would be cool. (edit: no longer needed)

What I have tried so far is calling readDetailFromDevice() 140 times with all different fit files on my device:

var fileType = "FitnessHistoryDetail";
controller.readDetailFromDevice(fileType, "2014-05-14T05:13:56Z");
controller.readDetailFromDevice(fileType, "2014-05-06T15:36:27Z");
[...]

it didn't crash but memory consumption went up to 7GB for the plugin container when I decided to kill the process (my host was getting really slow since swapping started). Clearly there is something wrong there...

adiesner commented 10 years ago

After commit c04fb56d012285479e0d6d7d4e95a497db6f05dc the situation is better, but not yet fully to my satisfaction.

The problem was that everytime readDetailFromDevice([id]) was called all fit files from the device have been opened to search for the correct file containing the track with the correct [id].

Which means your tracks on your device have been opened 17161 (131*131) times. Now I am storing an [id] to [file] map, which results in much lesser complete reads. There is still a memory leak somewhere so memory consumption still grows, but no longer that intense as it was before. I will continue to search for it.

adiesner commented 10 years ago

I just released 0.3.25 (ea15c091cfc93bcef4413d80967c8de13c706f47) - which should fix a memory leak problem and speed up the reading of tcx/fit files.

Could you test your problem again and see if the issue is still existing?

twistedpair commented 10 years ago

@adiesner Thanks for the enhancement!