Purego hangs on MacOS
MarkKremer opened this issue ยท 4 comments
Hi ๐
I'm creating this issue as a response to this issue in Beep.
@domingguss (thanks again), was able to run some of my test code. read from here onward. In summary:
If the following program is run using go run -v -a .
on a mac OS Big Sur 11.7.10 on a Intel Macbook Pro Late 2014.
package main
import (
"fmt"
_ "github.com/ebitengine/purego"
_ "github.com/ebitengine/purego/objc"
)
func init() {
fmt.Println("init()")
}
func main() {
fmt.Println("main()")
}
The following output is produced:
$ go run -v -a .
internal/goarch
internal/unsafeheader
internal/coverage/rtcov
internal/godebugs
internal/goos
internal/goexperiment
internal/cpu
runtime/internal/atomic
internal/itoa
internal/abi
runtime/internal/math
internal/chacha8rand
math/bits
runtime/internal/sys
unicode/utf8
internal/race
sync/atomic
cmp
unicode
slices
github.com/ebitengine/purego/internal/strings
internal/bytealg
math
runtime
internal/reflectlite
sync
internal/testlog
errors
sort
runtime/cgo
internal/safefilepath
internal/oserror
path
io
strconv
syscall
bytes
strings
reflect
regexp/syntax
internal/syscall/unix
internal/syscall/execenv
time
regexp
io/fs
internal/poll
internal/fmtsort
os
github.com/ebitengine/purego
fmt
github.com/ebitengine/purego/objc
example/hello
^Csignal: interrupt
After example/hello
is build, the program should output
init()
main()
Instead, the program blocks before it reaches the init
function. @domingguss manually quit the program after 5min.
This problem doesn't occur when Beep was using Oto <v1 but does occur on Oto v3. Beep skipped v2 so I don't have information about it.
Unfortunately I don't have a Mac so I can't reproduce the problem myself. But I hope some of the Beep users will hop over to help with any questions you may have.
I am not able to reproduce this on my M1 Max running macOS 14.4.1 with go 1.22.1 with any of the following configurations:
CGO_ENABLED=1 GOARCH=amd64 go run -v -a .
CGO_ENABLED=0 GOARCH=amd64 go run -v -a .
CGO_ENABLED=1 GOARCH=arm64 go run -v -a .
CGO_ENABLED=0 GOARCH=arm64 go run -v -a .
I do not have a way to test mac OS Big Sur 11.7.10. It would be helpful to know where it actually gets stuck if someone can figure that out. Some other follow up questions:
- Does it only hang when both purego and the objc package are imported?
- Does it happen with or without CGO_ENABLED=1/0?
- Which go versions are affected?
- Which purego version is in the go.mod?
When I re-tried 'my' scenario here, I couldn't reproduce it either.
Then I figured I hadn't cleared the go.mod
between testing the scenarios ๐
So when i try scenario 2:
package main
import (
"fmt"
_ "github.com/gopxl/beep/speaker"
)
func init() {
fmt.Println("init()")
}
func main() {
fmt.Println("main()")
}
and then this:
$ go get github.com/gopxl/beep/speaker
go: added github.com/ebitengine/oto/v3 v3.1.0
go: added github.com/ebitengine/purego v0.5.0
go: added github.com/gopxl/beep v1.4.0
go: added github.com/pkg/errors v0.9.1
go: added golang.org/x/sys v0.12.0
It only works when I changed purego's version to v0.7.0..
If it works on the latest version then it appears there is no issue - just update purego's version. Am I missing something?
You're correct. Thank you for your time. I've made a PR to add Dependabot to our project so we don't lag behind on versions in the future. :)