Why does meteor continue executing code after restart?

Hi,

Do you understand why
_ I have started a async method call to generate 100 apps (on remote server)
_ in the middle I restart meteor
_ after restart meteor continues! So how is this possible?

How can I reset meteor? Or how can I cancell the execution of a for each loop (what this code is doing for each customer: create an app)
thank you martijn

Same question for me !

I know this is an old topic, but I did not any useful answer to this problem. I am currently stuck with a Meteor.call(...) / Meteor.methods(...) only executed after the server restart.

Firstly, it’s working as designed: https://guide.meteor.com/methods.html#retries

Secondly, there are a couple of strategies for handling this:

If a client calls a method and is disconnected before it receives a response, it will re-call the method when it reconnects. This means that a client may call a method multiple times when it only means to call it once. If this behavior is problematic for your method, consider attaching a unique ID to each method call on the client, and checking on the server whether a call with this ID has already been made. Alternatively, you can use Meteor.apply with the noRetry option set to true.

4 Likes

Meteor works this way by default as @robfallows points out. Either explicitly invoke noRetry in your code, or if you’re just trying to work around it in development for now, the best way is to kill the process dead.

Otherwise if you just try to Ctrl-C out of it normally, the mongod child process will linger and indicate to the server that the method needs to be retried on startup.

I understand, but the thing is I am working on a project using Meteor 1.1.0.2 which is messy as I never saw, and the noRetry option is not available.

The client is not disconnected during the Meteor.call(...)

Could that be the cause if the Meteor.call(...) is in inside the callback of a HTTP.call(...) ?

Probably should upgrade, honestly.

And yes, you should test the method separately from your other asynchronous calls so you can properly isolate the problem. It could be that your HTTP.call is the issue.

You should test your methods, period. If there’s a bare minimum of testing you should do in a Meteor app, it’s your methods.

Check out and install meteortesting:mocha from Atmosphere using

meteor add meteortesting:mocha

Read up on https://mochajs.org/ as the bare minimum to use the package, and may I personally recommend http://sinonjs.org/, http://chaijs.com/, and http://chaijs.com/plugins/sinon-chai/

I noticed that the Meteor.call() was not declared inside a “Meteor context” (I don’t know if I can say that, and if there is kind of such context in Meteor mechanisms) and it was part of the problem.

Moving the Meteor.call() inside a Meteor.events() solved (partially) the problem. The Meteor.method() is called and the result is returned, even if the Meteor.call() is inside the callback of a HTTP.call().

Now I have to find why my Meteor.events() is not called when I uncomment some parts of the code… It looks like the same event is managed natively, with myInputElement.onchange(), and with a jQuery plugin… But that’s another story.

You can use Meteor.call anywhere - there is no “Meteor context” as such. I think we’ll need to see some code if we’re going to be able to help.