Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only defer client.Logout if client has been successfully returned. #2

Merged
merged 1 commit into from Sep 14, 2016

Conversation

lucaszhangyz
Copy link
Contributor

Hi Adrian,
Thanks for sharing these codes.
I found a bug which arised in the scenarios when error occured in vcenter.Connect(). Then when go exec the defer client.Logout(ctx) codes, a null point panic arised since client has never been initialized. A better idea is to move defer client.Logout(ctx) afer if err != nil codes. Here is the codes.

--- a/vsphere-influxdb.go
+++ b/vsphere-influxdb.go
@@ -131,12 +131,12 @@ func (vcenter *VCenter) Init(config Configuration) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := vcenter.Connect()

  •   defer client.Logout(ctx)
    if err != nil {
            errlog.Println("Could not connect to vcenter: ", vcenter.Hostname)
            errlog.Println("Error: ", err)
            return
    }
    
  •   defer client.Logout(ctx)
    var perfmanager mo.PerformanceManager
    

Best wishes
lucas

@sofixa sofixa merged commit 857020e into Oxalide:master Sep 14, 2016
@sofixa
Copy link
Member

sofixa commented Sep 14, 2016

Thanks a lot for this MR :)

Cheers,
Adrian

@cblomart
Copy link

cblomart commented Jun 3, 2017

Don't hesitate to report also to vsphere-graphite.
I've patched this back into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants