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

panic in goroutine deadlocks all routines and does not panic program #919

Open
traetox opened this issue Oct 27, 2021 · 0 comments
Open
Assignees
Labels
needsInvestigation Need to investigate

Comments

@traetox
Copy link
Contributor

traetox commented Oct 27, 2021

Suspected behavior

A panic in a scriggo originated go routine stalls the program, the panic does not propagate up and terminate the program.

Minimal Program

package main

func main() {
	count := 4
	ch := make(chan string, count)
	for i := 0; i < count; i++ {
		go runner(ch, string([]byte{0x30 + byte(i)}))
	}
	for {
		ch <- "stuff"
	}
}

func runner(ch chan string, id string) {
	if id == "3" {
		panic("stuff")
	}
	for val := range ch {
		println(id, val)
	}
}

GC output

1 stuff
0 stuff
0 stuff
0 stuff
0 stuff
panic: stuff

goroutine 20 [running]:
main.runner(0xc000096000, 0x4c8bd8, 0x1)
	/tmp/otest/main.go:16 +0x105
created by main.main
	/tmp/otest/main.go:7 +0x9b

Scriggo output

0 0
0 0
0 0
10 20
 1
 12 
1
12 1
 21 1

2 2
2 2
fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan send]:
reflect.chansend(0xc000074480, 0xc0000109a0, 0x100, 0x6db1e3)
	/opt/golang/go/src/runtime/chan.go:737 +0x4b
reflect.Value.send(0xc00011a540, 0xc000074480, 0x12, 0x691600, 0xc0000109a0, 0x198, 0xc000014300, 0x5)
	/opt/golang/go/src/reflect/value.go:1551 +0x11c
reflect.Value.Send(0xc00011a540, 0xc000074480, 0x12, 0x691600, 0xc0000109a0, 0x198)
	/opt/golang/go/src/reflect/value.go:1533 +0x93
github.com/open2b/scriggo/internal/runtime.(*VM).run(0xc00014a120, 0x203000)
	/home/kris/mygo/pkg/mod/github.com/open2b/[email protected]/internal/runtime/run.go:1583 +0x22a7
github.com/open2b/scriggo/internal/runtime.(*VM).runRecoverable(0xc00014a120, 0x0, 0x0)
	/home/kris/mygo/pkg/mod/github.com/open2b/[email protected]/internal/runtime/run.go:72 +0x85
github.com/open2b/scriggo/internal/runtime.(*VM).runFunc(0xc00014a120, 0xc00010d1e0, 0x0, 0x0, 0x0, 0x6b5a20, 0xc00011e320)
	/home/kris/mygo/pkg/mod/github.com/open2b/[email protected]/internal/runtime/run.go:32 +0xc5
github.com/open2b/scriggo/internal/runtime.(*VM).Run(0xc00014a120, 0xc00010d1e0, 0xc000010910, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/kris/mygo/pkg/mod/github.com/open2b/[email protected]/internal/runtime/vm.go:153 +0xa9
github.com/open2b/scriggo.(*Program).Run(0xc000109410, 0x0, 0xc000104f38, 0xc000109410)
	/home/kris/mygo/pkg/mod/github.com/open2b/[email protected]/programs.go:143 +0xd6
main.main()
	/tmp/scriggo_test/main.go:21 +0x158

Complete test program

package main

import (
	"fmt"

	"github.com/open2b/scriggo"
)

func main() {
	// Create a file system with the file of the program to run.
	fsys := scriggo.Files{"main.go": []byte(src)}

	opts := scriggo.BuildOptions{AllowGoStmt: true}

	// Build the program.
	program, err := scriggo.Build(fsys, &opts)
	if err != nil {
		panic(err)
	}
	// Run the program.
	err = program.Run(nil)
	if err != nil {
		fmt.Println("RUN ERROR", err)
	}
	fmt.Println("DONE")
}

const src = `
	package main

        func main() {
		count := 4
		ch := make(chan string, count)
		for i := 0; i < count; i++ {
			go runner(ch, string([]byte{0x30+byte(i)}))
		}
		for {
			ch<-"stuff"
		}
	}

	func runner(ch chan string, id string) {
		if id == "3" {
			panic("stuff")
		}
		for val := range ch {
			println(id, val)
		}
        }
`
@gazerro gazerro self-assigned this Oct 28, 2021
@gazerro gazerro added the needsInvestigation Need to investigate label Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needsInvestigation Need to investigate
Projects
None yet
Development

No branches or pull requests

2 participants