SAP / go-hdb

SAP HANA Database Client for Go
Apache License 2.0
168 stars 57 forks source link

Connecting to Hana Cloud instance from local system gives connection error #134

Closed subhankarc closed 7 months ago

subhankarc commented 7 months ago

I have created a Hana cloud instance and then created an hdi-shared instance. I am not trying to connect to the hdi-shared instance's key using the following sample code,

package main

import (
    "database/sql"
    "log"

    // Register hdb driver.
    _ "github.com/SAP/go-hdb/driver"
)

const (
    driverName   = "hdb"
    hdi_password = "xxxx"
    hdi_user     = "xxxx"
    user         = "xxxx"
    schema       = "xxxx"
    password     = "xxxx"
    host         = "xyz.hana.prod-xx.hanacloud.ondemand.com"
    port         = "443"
    hdbDsn       = "hdb://" + user + ":" + password + "@" + host + ":" + port + "?TLSServerName=" + host
)

func main() {
    db, err := sql.Open(driverName, hdbDsn)
    if err != nil {
        log.Println("Error on sql.Open: ", err)
        log.Panic(err)
    }
    defer db.Close()

    if err := db.Ping(); err != nil {
        log.Println("Error on db.Ping: ", err)
        log.Panic(err)
    }
}

In this case, the db.Ping() call fails with the following error.

$ go run main.go
2024/02/29 14:42:28 ERROR DB conn write error conn=1 error=EOF "local address"=10.53.211.121:50712 "remote address"=35.156.35.115:443
2024/02/29 14:42:28 ERROR DB conn write error conn=2 error=EOF "local address"=10.53.211.121:50728 "remote address"=35.156.35.115:443
2024/02/29 14:42:29 ERROR DB conn write error conn=3 error=EOF "local address"=10.53.211.121:50729 "remote address"=35.156.35.115:443
2024/02/29 14:42:29 Error on db.Ping:  driver: bad connection: EOF
2024/02/29 14:42:29 driver: bad connection: EOF
panic: driver: bad connection: EOF

goroutine 1 [running]:
log.Panic({0x1400002df00?, 0x0?, 0x2?})
        /opt/homebrew/Cellar/go/1.22.0/libexec/src/log/log.go:432 +0x60
main.main()
        /Users/xx/git/hana/main.go:33 +0x1e4
exit status 2

If I use hdbDsn = "hdb://" + user + ":" + password + "@" + host + ":" + port, then it fails with the following error.

$ go run main.go
2024/02/29 14:43:38 ERROR DB conn read error conn=1 error=EOF "local address"=10.53.211.121:51357 "remote address"=35.156.35.115:443
2024/02/29 14:43:44 ERROR DB conn read error conn=2 error=EOF "local address"=10.53.211.121:51412 "remote address"=3.76.142.27:443
2024/02/29 14:43:49 ERROR DB conn read error conn=3 error=EOF "local address"=10.53.211.121:51468 "remote address"=18.193.236.24:443
2024/02/29 14:43:49 Error on db.Ping:  driver: bad connection: EOF
2024/02/29 14:43:49 driver: bad connection: EOF
panic: driver: bad connection: EOF

goroutine 1 [running]:
log.Panic({0x1400002df00?, 0x0?, 0x2?})
        /opt/homebrew/Cellar/go/1.22.0/libexec/src/log/log.go:432 +0x60
main.main()
        /Users/xxx/git/hana/main.go:33 +0x1e4
exit status 2

Could you please help me what I am missing out on here ?

subhankarc commented 7 months ago

The problem was concerning the allowlisting.