scottdware / go-bigip

A Go package that interacts with F5 BIG-IP systems using the REST API.
MIT License
108 stars 118 forks source link

Panic runtime / error #76

Closed heterodyned closed 6 years ago

heterodyned commented 6 years ago

Hello!

I am using the following sample code

package main

import (
    "fmt"
    "bufio"
    "os"
    "github.com/scottdware/go-bigip"
)

func main() {

    // all_lbs.txt includes a list of F5 devices
    inFile, _ := os.Open("all_lbs.txt")

    scanner := bufio.NewScanner(inFile)
    for scanner.Scan() {
        line := scanner.Text()
        f5 := bigip.NewSession(line, "<credentials>", "<password>", nil)
        _ , err := f5.VirtualServers()
        if err != nil {
          fmt.Println(err)
          fmt.Println(line)
        }
    }

I notice a kernel panic error while iterating through a bunch of hosts.

Authorization failed: user=https://localhost/mgmt/shared/authz/users/<user>resource=/mgmt/tm/ltm/virtual verb=GET uri:http://localhost:8100/mgmt/tm/ltm/virtual referrer:10.220.112.195 sender:10.220.112.195
m0.llb001b.pod1.las1.as22023.net.
Authorization failed: user=https://localhost/mgmt/shared/authz/users/<user> resource=/mgmt/tm/ltm/virtual verb=GET uri:http://localhost:8100/mgmt/tm/ltm/virtual referrer:10.220.112.195 sender:10.220.112.195
m0.xlb001a.pod6.las1.as22023.net.
Authorization failed: user=https://localhost/mgmt/shared/authz/users/<user>
resource=/mgmt/tm/ltm/virtual verb=GET uri:http://localhost:8100/mgmt/tm/ltm/virtual referrer:10.220.112.195 sender:10.220.112.195
m0.xlb001b.pod6.las1.as22023.net.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x11e3892]

goroutine 1 [running]:
net/http.(*Request).SetBasicAuth(0x0, 0x129190a, 0x12, 0x12911f9, 0x10)
    /usr/local/go/src/net/http/request.go:882 +0x52
github.com/scottdware/go-bigip.(*BigIP).APICall(0xc420356000, 0xc420269da8, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/<username>/go/src/github.com/scottdware/go-bigip/bigip.go:164 +0x7d0
github.com/scottdware/go-bigip.(*BigIP).getForEntity(0xc420356000, 0x1222660, 0xc420454340, 0xc420269e48, 0x2, 0x2, 0x2a, 0xc42039c2a0, 0xc420062000)
    /Users/<username>/go/src/github.com/scottdware/go-bigip/bigip.go:261 +0xe6
github.com/scottdware/go-bigip.(*BigIP).VirtualServers(0xc420356000, 0x22, 0x129190a, 0x12)
    /Users/<username>/go/src/github.com/scottdware/go-bigip/ltm.go:1754 +0x98
main.main()
    /Users/<username>/projects/lb_api/lb.go:18 +0x155
exit status 2

Can someone recommend if I need to revise my code to highlight whats causing the nil pointer dereference? or if there is a bug lurking someplace?

heterodyned commented 6 years ago

Upon further investigation, there was some I/O issue with F5 which was affecting API interface, weirdly can't reproduce and provide enough context on how the library could catch this.