mweagle / Sparta

go microservices, powered by AWS Lambda
https://gosparta.io
MIT License
716 stars 48 forks source link

socket hang up #30

Closed h12w closed 7 years ago

h12w commented 7 years ago

I'm trying to run a CloudWatch cron job in Lambda, after the job is completed (I can tell from the log), the Lambda function fails with the error message below:

{
  "errorMessage": "socket hang up",
  "errorType": "Error",
  "stackTrace": [
    "createHangUpError (_http_client.js:200:15)",
    "Socket.socketOnEnd (_http_client.js:285:23)",
    "emitNone (events.js:72:20)",
    "Socket.emit (events.js:166:7)",
    "endReadableNT (_stream_readable.js:905:12)",
    "nextTickCallbackWith2Args (node.js:437:9)",
    "process._tickDomainCallback (node.js:392:17)"
  ]
}

It seems an error from Node.js. Any ideas?

mweagle commented 7 years ago

It's hard to tell from just this error message, but is it possible that the Go function isn't writing a response to http.ResponseWriter as in:

// Standard AWS λ function
func helloWorld(event *json.RawMessage,
    context *sparta.LambdaContext,
    w http.ResponseWriter,
    logger *logrus.Logger) {

       // Job logic

    fmt.Fprint(w, "Job complete")
}
h12w commented 7 years ago

It seems to be related to a 10-seconds timeout in the Node.js wrapper, and can be reproduced with code below:

func helloWorld(event *json.RawMessage,
    context *sparta.LambdaContext,
    w http.ResponseWriter,
    logger *logrus.Logger) {

    for i := 0; i < 11; i++ {
        w.Write([]byte(strconv.Itoa(i)))
        logger.Infof("%d", i)
        time.Sleep(time.Second)
    }

}

BTW, writing something with ResponseWriter does not help.

mweagle commented 7 years ago

Thanks for the details - investigating.

h12w commented 7 years ago

[workaround]

I cannot wait for the fix, so I have switched to eawsy/aws-lambda-go. It does not provide CloudWatch triggers but the deployment is a lot faster than Sparta.

mweagle commented 7 years ago

Appreciate the update - I still would like to resolve this issue, but need some additional diagnostic information. If you do end up switching back to Sparta, please re-open.