Debug client-server communication - problem with long async call


In my app I have sth like this (below very simplified picture which present main idea of the code):

client-side:‘doLongCalc’, params, function(err, result) {
  Session.set(“CalculationStatus”, “All Done”);
  console.log(“calculation finished”);


‘doLongCalc’: function(params) {
mongoData=Collection.find( { …} );
for (var i=0; i < 10e8; i++) {
  results.push( doSmallPartOfCalculation(params, mongoData) );
console.log(“calculation done”);
return “done”;

Such code works fine but slow. Data from mongo never change during calculation so I decided to pass fetched object not mongo cursor:

mongoData=Collection.find( { …} ).fetch();

The change speedup my calculation but in some situation (long calculation for some data) it can cause either “infinity loop” (meteor 1.5) or user logout (meteor 1.6beta).
I tried to investigate the problem on stable meteor 1.5. Based on server and client logs it seems that doLongCalc do all jobs (inserts data to mongo, prints message) but client does not receive this information ( Session is never set and message is never print) and after while client call function again (or by some other reason it is invoke again and again).

It is extremely strange for me (and I guess for all readers :slight_smile: ) I have no idea why so small and irrelevant change can cause this (and probably no one knows). I am asking for help in debugging this situation, what can I do to get any information whats going on during this async call between server and client? How to debug such strange situation?