rgbkrk / libvirt-go

[DEPRECATED] Go bindings for libvirt
https://github.com/libvirt/libvirt-go
MIT License
166 stars 50 forks source link

libvirt.VirConnection.ListDomains causes memory corruption #1

Closed Doridian closed 10 years ago

Doridian commented 10 years ago

As soon as I used ListDomains and after that try to use net.Listen (or net.ANYTHING, really), this happens: LookupDomainBy* and then getting info about the domain works fine, gives correct results and does not break anything.

unexpected fault address 0x2100000022 fatal error: fault [signal 0xb code=0x1 addr=0x2100000022 pc=0x40dec9]

goroutine 1 [running]: [fp=0x7f1807c27850] runtime.throw(0x8c8ef7) /usr/lib/go/src/pkg/runtime/panic.c:473 +0x67 [fp=0x7f1807c27868] runtime.sigpanic() /usr/lib/go/src/pkg/runtime/os_linux.c:239 +0xe7 [fp=0x7f1807c278a8] runtime.MCache_Alloc(0x7f1807c57000, 0x3, 0x20, 0x1) /usr/lib/go/src/pkg/runtime/mcache.c:33 +0xd9 [fp=0x7f1807c27900] runtime.mallocgc(0x20, 0x100000001, 0x1) /usr/lib/go/src/pkg/runtime/zmalloc_linux_amd64.c:47 +0xf5 [fp=0x7f1807c27930] runtime.new() /usr/lib/go/src/pkg/runtime/zmalloc_linux_amd64.c:628 +0x5b [fp=0x7f1807c279d0] syscall.anyToSockaddr(0xc2000ca8c0, 0xc2000ca8c0, 0xc200000640, 0x0, 0x0, ...) /usr/lib/go/src/pkg/syscall/syscall_linux.go:405 +0x19b [fp=0x7f1807c27a08] syscall.Getsockname(0x7, 0x0, 0x0, 0x0, 0x0, ...) /usr/lib/go/src/pkg/syscall/syscall_linux.go:463 +0xb6 [fp=0x7f1807c27a70] net.socket(0x5d1c60, 0x4, 0x2, 0x1, 0x0, ...) /usr/lib/go/src/pkg/net/sock_posix.go:70 +0x403 [fp=0x7f1807c27b48] net.internetSocket(0x5d1c60, 0x4, 0xc200088140, 0xc2000d1c30, 0x0, ...) /usr/lib/go/src/pkg/net/ipsock_posix.go:146 +0x423 [fp=0x7f1807c27c10] net.ListenTCP(0x5d1c60, 0x4, 0xc2000d1c30, 0xc2000d1c30, 0x5d4701, ...) /usr/lib/go/src/pkg/net/tcpsock_posix.go:289 +0x16f [fp=0x7f1807c27cc8] net.Listen(0x5d1c60, 0x4, 0x5d4770, 0xc, 0xc200069dc0, ...) /usr/lib/go/src/pkg/net/dial.go:193 +0x277 [fp=0x7f1807c27f90] main.main() /home/xenmanage/gonode/node.go:46 +0x448 [fp=0x7f1807c27fb8] runtime.main() /usr/lib/go/src/pkg/runtime/proc.c:182 +0x92 [fp=0x7f1807c27fc0] runtime.goexit() /usr/lib/go/src/pkg/runtime/proc.c:1223

goroutine 2 [syscall]:

goroutine 3 [runnable]: exit status 2

alexzorin commented 10 years ago

Hi @Doridian

I wasn't able to reproduce this using the test driver. Under which OS/libvirt driver/go version did you observe this happening?

Did I interpret your story correctly in the test?

Doridian commented 10 years ago

Your test seems correct. My go version is: go version go1.1.2 linux/amd64

Doridian commented 10 years ago

However also see my pull request which does not expose the bug (and GitHub seems to have added all my other commits now, too. Ah well...)

Doridian commented 10 years ago

Oh and for the rest of infos:

virsh version

Compiled against library: libvirt 1.1.1 Using library: libvirt 1.1.1 Using API: QEMU 1.1.1 Running hypervisor: QEMU 1.5.0

uname -a

Linux server 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

alexzorin commented 10 years ago

Thanks, I will try to replicate your environment at some point.

Doridian commented 10 years ago

Its a standard Ubuntu 13.10 64-bit (only packages from the official Ubuntu apt repo, nothing compiled from source)

nguillaumin commented 10 years ago

Hi,

I'm also experiencing this issue on CentOS 6.5 x64. Using @Doridian branch seem to fix it. Any chance you could merge the patch, or at least just the commit to fix the memory corruption issue?

Cheers,

Nico

alexzorin commented 10 years ago

Cherry-picked the ListDomains fix, thanks @Doridian

nguillaumin commented 10 years ago

Unfortunately the patch causes 2 imports to now be unused, so it doesn't build anymore:

src/github.com/alexzorin/libvirt-go/libvirt.go:4: imported and not used: "bytes"
src/github.com/alexzorin/libvirt-go/libvirt.go:5: imported and not used: "encoding/binary"
alexzorin commented 10 years ago

Thanks, I didn't have a test env at the time