0

I'm using googleapis (NodeJS) with AWS lambda functions that create calendar invitations on behalf of users.

  1. Get the available timeslots using google.calendar.freebusy.query()
  2. Creates the invitation using google.calendar.events.insert()

Step 1 works just fine. But recently, step 2 started throwing this error:

FetchError: request to https://www.googleapis.com/calendar/v3/calendars/primary/events?sendUpdates=all failed, reason: socket hang up

The error happens only when deployed to AWS. It works fine locally using serverless-offline. Also, if I try 10 times, about 1 - 2 of them create the invitation and the rest fails. When it fails, it takes about 5-8 minutes to display the error.

Any guide on this would be much appreciated.

Server env:

  • Node v14.17.2
  • googleapis 95.0.0 (Tried downgrading to 89, 76 & 59 and that doesn't work)
  • serverless v1.83.3

Creating invitations:

await googleCalendar.events.insert(
    {
      sendUpdates: "all",
      calendarId: "primary",
      resource: newEvent,
    },
    (err, res) => {
      if (err) {
        console.log('Failed to send the invitation', error)
        // this is where I'm catching the above error
      }
    }
  );
Mahesh Samudra
  • 1,039
  • 1
  • 11
  • 25
  • Does this answer your question? [NodeJS - What does "socket hang up" actually mean?](https://stackoverflow.com/questions/16995184/nodejs-what-does-socket-hang-up-actually-mean) – Linda Lawton - DaImTo Feb 17 '22 at 08:21
  • [@Daimto](https://stackoverflow.com/users/1841839/daimto) I read the answers. It explains the reason for the error. I'm working on retrying after the error. And in the Google logs, it doesn't reflect any errors. It only captures the successful attempts. Not the failed ones. Does that mean the request never reaches Google's API? – Mahesh Samudra Feb 17 '22 at 10:04
  • 1
    Hey, @MaheshSamudra I did answer a similar question the other day, check if the code helps you to see anything different from what you're trying to do, it runs on AWS Lambda, a similar scenario, creating a new event https://stackoverflow.com/a/70759245/411077 – Ruben Restrepo Feb 17 '22 at 17:43
  • Hi Ruben Restrepo, thank you for the comment. I was following what was mentioned in Google's documentation: https://developers.google.com/calendar/api/guides/create-events#metadata. However, your method works. But I have no idea why that happens, maybe Google needs to update the docs. Also, can you post this as an answer? – Mahesh Samudra Feb 18 '22 at 09:13

0 Answers0