Skip to content

Golang Process exited before completing request when connecting to RDS Mysql DB #55

Description

@prakashsanker

Hey,

So I'm connecting to a RDS Mysql DB using golang's sql driver.

I do so like this

func main() {
  db, err := sql.Open("mysql", "db_details")
  err = db.Ping()
  if err != nil {
    fmt.Println("Failed to prepare connection to database")
    // log.Fatal("Error:", err.Error())
  }
    apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
      fmt.Println(ctx)
      return map[string]string{"hello": "world"}, nil
    })
}

The function is called getTags and I get this error when I do apex invoke getTags

Process exited before completing request

This doesn't look like a run time error, as a Println put right before the sql.Open doesn't run.

From looking around, most of the examples are in node and indicate that I need to do a context.done or raise the timeout.

I increased the timeout to 300s and the same error occurred.

I then looked around the source code to see if the Context type had a Done function defined on it...but it doesn't look like it does.

I looked at the logs and found this

/aws/lambda/chanakya-serverless-api_getTags panic: runtime error: invalid memory address or nil pointer dereference
/aws/lambda/chanakya-serverless-api_getTags [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x47b8ba]
/aws/lambda/chanakya-serverless-api_getTags 
goroutine 1 [running]:
/aws/lambda/chanakya-serverless-api_getTags panic(0x4d9780, 0xc42000a030)
/aws/lambda/chanakya-serverless-api_getTags 	/Users/psanker/.gvm/gos/go1.7/src/runtime/panic.go:500 +0x1a1
/aws/lambda/chanakya-serverless-api_getTags database/sql.(*DB).conn(0x0, 0x4cfd01, 0xc42000a340, 0x4f5cef, 0x5)
/aws/lambda/chanakya-serverless-api_getTags 	/Users/psanker/.gvm/gos/go1.7/src/database/sql/sql.go:781 +0x3a
/aws/lambda/chanakya-serverless-api_getTags database/sql.(*DB).Ping(0x0, 0x5, 0x4fd4c0)
/aws/lambda/chanakya-serverless-api_getTags 	/Users/psanker/.gvm/gos/go1.7/src/database/sql/sql.go:503 +0x34
/aws/lambda/chanakya-serverless-api_getTags main.main()
/aws/lambda/chanakya-serverless-api_getTags 	/Users/psanker/chanakya-serverless-api/functions/getTags/main.go:13 +0xe6

So I then went to a non-apex version of the code (I'm porting a codebase over) and tried the same code...and everything worked, so I'm not sure why there is a segfault.

What is the way around this? Why is this happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions