0

In my Meteor app, I am making outbound HTTP GET requests on an interval like such:

Meteor.setInterval(function () {
  try {
    var request = Meteor.http.call("GET", <url>, {
      params: <params>,
      timeout: <timeout>
    });
  }
  catch (err) {
    console.log(err);
    request = undefined;
  }
  if (request.statusCode === 200) {
    // handle the response
    ...
  }
}, 10000);

If I let this run for a few minutes, I start getting errors logged to console via the catch block: Error: socket hang up.

What is causing these errors and how can they be mitigated? According to this SO post, the request needs to be told to .end();, but I'm not sure if this is correct or how to do this in Meteor. Thanks!

Community
  • 1
  • 1
Jon Cursi
  • 3,301
  • 4
  • 27
  • 53

1 Answers1

0

have you tried this.response.end(); I use it in my router listening to webhooks and it works fine

416serg
  • 348
  • 2
  • 17
  • where would that line go in the example above? no matter where i put it, I get this: ` TypeError: Cannot call method 'end' of undefined` – Jon Cursi Mar 04 '15 at 04:51
  • @JonCursi apologies, you should be doing `request.end()` – 416serg Mar 04 '15 at 05:22
  • I tried that too, no luck. On exactly what line above should I put that? Maybe I'm inserting it in the wrong spot? – Jon Cursi Mar 05 '15 at 04:24
  • @JonCursi I'd put it after you handle the response inside the `if` statement – 416serg Mar 05 '15 at 17:25
  • no luck, doesn't seem like making a synchronous HTTP request like I have above creates an `end` method on the `request` object that I can use. Getting `[Object object] has no method 'end'` – Jon Cursi Mar 06 '15 at 00:37
  • @JonCursi are you using ngrok to test it out? are you seeing any status 200's in there? – 416serg Mar 06 '15 at 01:11