oVirt / ovirt-engine-sdk-go

The generator of Go SDK for oVirt v4.0+
Apache License 2.0
19 stars 23 forks source link

Check if response is not nil #215

Closed bennyz closed 4 years ago

bennyz commented 4 years ago

Description of the Change

Before executing the relevant FollowLink method, make sure the response we got from the engine is not nil, otherwise the response object will be nil and panic.

Alternate Designs

Benefits

This is a bug fix. If ovirt-engine is not accessible before a FollowLink call, it will panic because the response object will be nil.

Possible Drawbacks

Verification Process

This can be reproduced easily by terminating the ovirt-engine process right before the FollowLink call, an example stack trace would look like this:

[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xca3385]

goroutine 1 [running]:
github.com/ovirt/go-ovirt.(*DiskServiceGetResponse).Disk(0x0, 0x0, 0x0)
        /home/bzlotnik/Development/go/src/github.com/ovirt/go-ovirt/services.go:119416 +0x5
reflect.Value.call(0x102ce60, 0xc0001cb468, 0x293, 0x114312e, 0x4, 0xc0001c5c58, 0x0, 0x0, 0x0, 0x0, ...)
        /usr/lib/golang/src/reflect/value.go:460 +0x8ab
reflect.Value.Call(0x102ce60, 0xc0001cb468, 0x293, 0xc0001c5c58, 0x0, 0x0, 0x1, 0xc, 0x0)
        /usr/lib/golang/src/reflect/value.go:321 +0xb4
github.com/ovirt/go-ovirt.(*Connection).FollowLink(0xc00015a000, 0x128ba60, 0xc0001351e0, 0x1, 0x1, 0x14, 0x0)
        /home/bzlotnik/Development/go/src/github.com/ovirt/go-ovirt/connection.go:172 +0x7d2
main.main()
        ...

I used this snippet[1] to reproduce, with my patch the result is:

sleep before follow
follow failed: Failed to get response

https://gist.github.com/bennyz/d5b5f5112aa4b1ea27b6dc41791a8fab

Applicable Issues

imjoey commented 4 years ago

@bennyz LGTM. Nice catch. Thank you very much for this. Let's merge this.