HTTP request times out with Galaxy


#1

I have some code that works perfectly in development and in staging but doesn’t work in production (which is AFAICT identical to staging). The production and staging environments are hosted on Galaxy.

The code is pretty simple. It makes requests using Meteor’s HTTP package (synchronously) to a 3rd party API in order to send an email.

The problem is that it’s timing out after the 29 seconds. I’ve tried the request locally via meteor shell and it works just fine.

The only thing I can think of is that somehow my production Galaxy container is blocking the execution of the HTTP request. The error appears to be isolated to certain accounts / users.

This is my mailer class:

import { HTTP } from 'meteor/http';

export default class CampaignMailer {

  constructor(jobData) {
    this.email = jobData.email;
    this.nylasToken = jobData.metadata.nylasToken;
  }

  send() {
    return HTTP.call(
      'POST',
      'https://api.nylas.com/send', {
        auth: `${this.nylasToken}:`,
        data: {
          to: this.email.to,
          bcc: this.email.bcc,
          body: this.email.html,
          subject: this.email.subject,
        },
        // Always ensure this is less than the timeout on the worker
        timeout: 29000,  // 29 seconds
      }
    );
  }
}

Even if I start / stop / redeploy the app I still have issues with these specific accounts. Any ideas, anyone? I’ve spent the entire day pulling my hair out on this one!


#2

Further to this, I added code to log out the options passed to HTTP.call so I could run it locally in the Meteor shell. It works perfectly every time and returns within a few seconds. The exact same request! I’m baffled.

One other thing that’s strange is that some requests do succeed but only after HTTP.call has timed out and only after a long time. For example, I made 6 attempts between 07:27 and 07:32 (about one per minute). As of writing, two of these have come through (as emails to my inbox) arriving at 07:37 and 07:55. Just to re-iterate, if I do the same query locally (a few seconds after) it always returns within a few seconds.

I’ve contacted Galaxy support. I’ve wasted ages on this one.

EDIT: I also tried rewriting the code to use https://github.com/request/request rather than HTTP but it fails just the same. I know HTTP uses request under the hood on the server side so I guess this was a bit of a long shot.


#3

maybe the AWS container this runs on does not allow outbound traffic?


#4

Hey @jamgold. Thanks for chiming in. I actually managed to work this one out via another question I asked — HTTP Requests time out with Production Compose Database only

It turns out that I was attempting to make too many outbound connections from Node and was hitting the limits.