[GH-ISSUE #120] Invalid memory address or nil pointer dereference on vm.Delete() #23

Closed
opened 2026-03-03 15:29:40 +03:00 by kerem · 2 comments
Owner

Originally created by @SnelsSM on GitHub (Feb 25, 2024).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/120

Hi!
Function Delete for VM fails with
runtime error: invalid memory address or nil pointer dereference

My code

ctx := context.Background()
// Use vm.Status != "stopped" because vm.IsStopped()/vm.IsRunning() always returns 'false'
if vm.Status != "stopped" {
	task, err := vm.Stop(ctx)
	if err != nil {
		log.Error(err)
		return err
	}
	status, completed, err := task.WaitForCompleteStatus(ctx, 10, 3, 5, 10)
	if err != nil {
		return err
	}
	if !status && !completed {
		return fmt.Errorf("cannot stop vm %v", vmid)
	}
}

task, err := vm.Delete(ctx)
if err != nil {
	log.Error(err)
	return err
}
status, completed, err := task.WaitForCompleteStatus(ctx, 10, 3, 5, 10)
if err != nil {
	return err
}
if !status && !completed {
	return fmt.Errorf("cannot delete vm %v", vmid)
}

vm.Stop works but vm.Delete fails

runtime error: invalid memory address or nil pointer dereference
/usr/lib/go/src/runtime/panic.go:261 (0x450ef7)
        panicmem: panic(memoryError)
/usr/lib/go/src/runtime/signal_unix.go:861 (0x450ec5)
        sigpanic: panicmem()
/home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:54 (0x940e5b)
        (*VirtualMachine).HasTag: if v.VirtualMachineConfig.Tags == "" {
/home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:337 (0x943616)
        (*VirtualMachine).deleteCloudInitISO: if v.HasTag(MakeTag(TagCloudInit)) {
/home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:324 (0x943436)
        (*VirtualMachine).Delete: if ok, err := v.deleteCloudInitISO(ctx); err != nil || !ok {
/home/snels/git/pve-api-gateway/pkg/pve/vm.go:542 (0x952464)
        deleteVM: task, err := vm.Delete(ctx)

Am I doing something wrong or is the problem in the module?

Originally created by @SnelsSM on GitHub (Feb 25, 2024). Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/120 Hi! Function Delete for VM fails with ```runtime error: invalid memory address or nil pointer dereference``` My code ``` ctx := context.Background() // Use vm.Status != "stopped" because vm.IsStopped()/vm.IsRunning() always returns 'false' if vm.Status != "stopped" { task, err := vm.Stop(ctx) if err != nil { log.Error(err) return err } status, completed, err := task.WaitForCompleteStatus(ctx, 10, 3, 5, 10) if err != nil { return err } if !status && !completed { return fmt.Errorf("cannot stop vm %v", vmid) } } task, err := vm.Delete(ctx) if err != nil { log.Error(err) return err } status, completed, err := task.WaitForCompleteStatus(ctx, 10, 3, 5, 10) if err != nil { return err } if !status && !completed { return fmt.Errorf("cannot delete vm %v", vmid) } ``` vm.Stop works but vm.Delete fails ``` runtime error: invalid memory address or nil pointer dereference /usr/lib/go/src/runtime/panic.go:261 (0x450ef7) panicmem: panic(memoryError) /usr/lib/go/src/runtime/signal_unix.go:861 (0x450ec5) sigpanic: panicmem() /home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:54 (0x940e5b) (*VirtualMachine).HasTag: if v.VirtualMachineConfig.Tags == "" { /home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:337 (0x943616) (*VirtualMachine).deleteCloudInitISO: if v.HasTag(MakeTag(TagCloudInit)) { /home/snels/go/pkg/mod/github.com/luthermonson/go-proxmox@v0.0.0-beta3/virtual_machine.go:324 (0x943436) (*VirtualMachine).Delete: if ok, err := v.deleteCloudInitISO(ctx); err != nil || !ok { /home/snels/git/pve-api-gateway/pkg/pve/vm.go:542 (0x952464) deleteVM: task, err := vm.Delete(ctx) ``` Am I doing something wrong or is the problem in the module?
kerem closed this issue 2026-03-03 15:29:40 +03:00
Author
Owner

@luthermonson commented on GitHub (Feb 25, 2024):

how did you make the vm you are making these Delete calls against? because it's complaining that the vm config is nil and that is populated here: https://github.com/luthermonson/go-proxmox/blob/main/nodes.go#L76-L78

did you not make the vm via node.VirtualMachine(ctx, id)?

<!-- gh-comment-id:1963032959 --> @luthermonson commented on GitHub (Feb 25, 2024): how did you make the vm you are making these Delete calls against? because it's complaining that the vm config is nil and that is populated here: https://github.com/luthermonson/go-proxmox/blob/main/nodes.go#L76-L78 did you not make the vm via `node.VirtualMachine(ctx, id)`?
Author
Owner

@luthermonson commented on GitHub (Feb 25, 2024):

you can use beta4 release now which has a nil check and won't error there... the delete is checking for an existing cloud init iso made by the package and if the config is empty it can't really do that so we will just continue on. you should consider before manipulating your vms though to pull full info for the vm via node.VirtualMachine as it gives you the most complete information for that vm

<!-- gh-comment-id:1963039912 --> @luthermonson commented on GitHub (Feb 25, 2024): you can use [beta4](https://github.com/luthermonson/go-proxmox/releases/tag/v0.0.0-beta4) release now which has a nil check and won't error there... the delete is checking for an existing cloud init iso made by the package and if the config is empty it can't really do that so we will just continue on. you should consider before manipulating your vms though to pull full info for the vm via node.VirtualMachine as it gives you the most complete information for that vm
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-proxmox#23
No description provided.