Skip to content

garbage collection issue in FreeBSD #376

Closed
@dhobsd

Description

@dhobsd
What steps will reproduce the problem?
1. Create a test.go with

package main

import (
       "fmt";
       "os";
       "runtime";
)

func process(file string, c chan string) {
       fmt.Printf("processing %s...\n", file);
       for i := uint(0); i < 1<<31; i++ {}
       c <- file
}

func main() {
       runtime.GOMAXPROCS(4);

       c := make(chan string);

       for i := 1; i < len(os.Args); i++ {
               go process(os.Args[i], c)
       }

       for i := 1; i < len(os.Args); i++ {
               fmt.Printf("Done processing %s\n", <-c);
       }
}

2. Compile and Run on FreeBSD

What is the expected output? What do you see instead?

Occasionally (maybe 50% of the time) it runs properly. The rest of the
time, I either get segfaults in MCentral_Free (looks like it's trying to
free nil) or the following trace:

> ./6.out a b c
processing a...
processing b...
odd span state=0 span=0xa1000d8a68 base=0xa1001b0000 sizeclass=10 n=27
size=144 npages=1
s->base sizeclass 10 v=0xa1001b0000 base=0xa1001b0000 gcref=0xa10024c9f0
blocksize=4096 nobj=27 size=144 end=0xa10024ca5c end=0xa1001b1000
throw: bad gcref

panic PC=0xa10019c478
throw+0x3e /usr/home/dho/golang/src/pkg/runtime/runtime.c:74
        throw(0x441e46, 0x0)
mlookup+0x270 /usr/home/dho/golang/src/pkg/runtime/malloc.c:164
        mlookup(0x1b0000, 0xa1, 0x0, 0x0, 0x0, ...)
malloc+0xe7 /usr/home/dho/golang/src/pkg/runtime/malloc.c:47
        malloc(0x90, 0x0)
malg+0x1e /usr/home/dho/golang/src/pkg/runtime/proc.c:737
        malg(0x8000, 0x0)
minit+0x1b /usr/home/dho/golang/src/pkg/runtime/freebsd/thread.c:164
        minit()
mstart+0x42 /usr/home/dho/golang/src/pkg/runtime/proc.c:392
        mstart()
thr_start+0xb /usr/home/dho/golang/src/pkg/runtime/freebsd/amd64/sys.s:32
        thr_start()

goroutine 4 [1]:
goexit /usr/home/dho/golang/src/pkg/runtime/proc.c:135
        goexit()
0xa100147018 unknown pc

goroutine 3 [2]:
runtime·entersyscall+0x50 /usr/home/dho/golang/src/pkg/runtime/proc.c:545
        runtime·entersyscall()
syscall·Syscall+0x5b
/usr/home/dho/golang/src/pkg/syscall/asm_freebsd_amd64.s:46
        syscall·Syscall()
syscall·Write+0x5d /usr/home/dho/golang/src/pkg/syscall/exec.go:17
        syscall·Write(0x1, 0xa1, 0x171c40, 0xa1, 0x10, ...)
os·*File·Write+0x5f /usr/home/dho/golang/src/pkg/os/file.go:162
        os·*File·Write(0x172d50, 0xa1, 0x171c40, 0xa1, 0x10, ...)
fmt·Fprintf+0xe8 /usr/home/dho/golang/src/pkg/fmt/print.go:214
        fmt·Fprintf(0x1af000, 0xa1, 0x172d50, 0xa1, 0x45a9d0, ...)
fmt·Printf+0x72 /usr/home/dho/golang/src/pkg/fmt/print.go:220
        fmt·Printf(0x45a9d0, 0x0, 0x11, 0x0, 0x444c18, ...)
main·process+0x5a /usr/home/dho/test.go:9
        main·process(0x147010, 0xa1, 0x1, 0x0, 0x192000, ...)
goexit /usr/home/dho/golang/src/pkg/runtime/proc.c:135
        goexit()
0xa100147010 unknown pc

goroutine 2 [2]:
runtime·entersyscall+0x50 /usr/home/dho/golang/src/pkg/runtime/proc.c:545
        runtime·entersyscall()
syscall·Syscall+0x5b
/usr/home/dho/golang/src/pkg/syscall/asm_freebsd_amd64.s:46
        syscall·Syscall()
syscall·Write+0x5d /usr/home/dho/golang/src/pkg/syscall/exec.go:17
        syscall·Write(0x1, 0xa1, 0x171840, 0xa1, 0x10, ...)
os·*File·Write+0x5f /usr/home/dho/golang/src/pkg/os/file.go:162
        os·*File·Write(0x172d50, 0xa1, 0x171840, 0xa1, 0x10, ...)
fmt·Fprintf+0xe8 /usr/home/dho/golang/src/pkg/fmt/print.go:214
        fmt·Fprintf(0x1af000, 0xa1, 0x172d50, 0xa1, 0x45a9d0, ...)
fmt·Printf+0x72 /usr/home/dho/golang/src/pkg/fmt/print.go:220
        fmt·Printf(0x45a9d0, 0x0, 0x11, 0x0, 0x444c18, ...)
main·process+0x5a /usr/home/dho/test.go:9
        main·process(0x147008, 0xa1, 0x1, 0x0, 0x192000, ...)
goexit /usr/home/dho/golang/src/pkg/runtime/proc.c:135
        goexit()
0xa100147008 unknown pc

goroutine 1 [4]:
gosched+0x34 /usr/home/dho/golang/src/pkg/runtime/proc.c:521
        gosched()
chanrecv+0x318 /usr/home/dho/golang/src/pkg/runtime/chan.c:319
        chanrecv(0x192000, 0xa1, 0x174f80, 0xa1, 0x0, ...)
runtime·chanrecv1+0x50 /usr/home/dho/golang/src/pkg/runtime/chan.c:415
        runtime·chanrecv1(0x192000, 0xa1)
main·main+0xc3 /usr/home/dho/test.go:23
        main·main()
mainstart+0xf /usr/home/dho/golang/src/pkg/runtime/amd64/asm.s:54
        mainstart()
goexit /usr/home/dho/golang/src/pkg/runtime/proc.c:135
        goexit()
Segmentation fault (core dumped)

What is your $GOOS?  $GOARCH?
freebsd/amd64

Which revision are you using?  (hg identify)
68ebc44e8429 tip


Please provide any additional information below.
Looks like it's my bug and my problem :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions