Part of #1230 When reusing an already-running Ryuk reaper, testcontainers-go v0.43.0 waits only for its Docker port mapping. Docker exposes that port before Ryuk is listening, so a second package can connect too early and lose the handshake with `read ack: EOF`. That is [testcontainers-go#3743](https://github.com/testcontainers/testcontainers-go/issues/3743); v0.44.0 also waits for the reaper's `Started` log line ([#3761](https://github.com/testcontainers/testcontainers-go/pull/3761)). A package whose handshake fails is not counted as a Ryuk client but its containers still carry the shared session label, so another package exiting can delete a database that is still in use — the failure reported in #1230. ## Scope This helps local runs, where the reaper stays on. **It does not fix CI on its own**, so it is deliberately separate from #1235, which disables the reaper for `run-tests`. Measured on a 4-core Linux VM with cold build caches, which staggers package start times the way CI does: ``` v0.43.0, 3 rounds handshake failures in 3/3 rounds; one round cascaded v0.44.0, 3 rounds no handshake failures; database tests still unavailable in 3/3 rounds ``` Under v0.44.0 the failures move to `wait for reaper <id>: context deadline exceeded` — a late package finds a reaper that is already shutting down, and one readiness probe (`defaultStartupTimeout`, 60s) outlives the whole reaper retry budget (`MaxElapsedTime`, 20s), so the retry loop never gets a second attempt. The remaining fail-open behind all of this is [#3827](https://github.com/testcontainers/testcontainers-go/issues/3827), still open upstream. ## Diff size Four lines of `go.mod`. The rest is `go mod vendor` output: v0.44.0 pulls newer `moby/client`, `gopsutil`, and `otelhttp`, and `otelhttp` moves `otel/semconv` from v1.39.0 to v1.41.0. Insertions and deletions nearly cancel because most of it is a directory swap and one generated `httpsnoop` file being merged into another. ``` go.mod, go.sum 62 lines vendor/ 61 files, 17356 +/17490 - ``` `hack/verify/go-modules.sh`, `licenses.sh`, `boilerplate.sh`, and `gofmt.sh` all pass; `go test -race ./cmd/ateapi/...` is green with no silently skipped database tests. --- - [x] Tests pass - [x] Appropriate changes to documentation are included in the PR
purego
A library for calling C functions from Go without Cgo.
This is beta software so expect bugs and potentially API breaking changes but each release will be tagged to avoid breaking people's code. Bug reports are encouraged.
Motivation
The Ebitengine game engine was ported to use only Go on Windows. This enabled
cross-compiling to Windows from any other operating system simply by setting GOOS=windows. The purego project was
born to bring that same vision to the other platforms supported by Ebitengine.
Benefits
- Simple Cross-Compilation: No C means you can build for other platforms easily without a C compiler.
- Faster Compilation: Efficiently cache your entirely Go builds.
- Smaller Binaries: Using Cgo generates a C wrapper function for each C function called. Purego doesn't!
- Dynamic Linking: Load symbols at runtime and use it as a plugin system.
- Foreign Function Interface: Call into other languages that are compiled into shared objects.
- Cgo Fallback: Works even with CGO_ENABLED=1 so incremental porting is possible. This also means unsupported GOARCHs (freebsd/riscv64, linux/mips, etc.) will still work except for float arguments and return values.
Supported Platforms
Tier 1
Tier 1 platforms are the primary targets officially supported by PureGo. When a new version of PureGo is released, any critical bugs found on Tier 1 platforms are treated as release blockers. The release will be postponed until such issues are resolved.
- Android: amd641, arm641
- iOS: amd641, arm641
- Linux: amd64, arm64
- macOS: amd64, arm64
- Windows: amd64, arm64
Tier 2
Tier 2 platforms are supported by PureGo on a best-effort basis. Critical bugs on Tier 2 platforms do not block new PureGo releases. However, fixes contributed by external contributors are very welcome and encouraged.
- Android: 3861, arm1
- FreeBSD: amd642, arm642
- Linux: 386, arm, loong64, ppc64le, riscv64, s390x1
- Windows: 3863, arm3,4
Support Notes
- These architectures require CGO_ENABLED=1 to compile
- These architectures require the special flag
-gcflags="github.com/ebitengine/purego/internal/fakecgo=-std"to compile with CGO_ENABLED=0 - These architectures only support
SyscallNandNewCallback - These architectures are no longer supported as of Go 1.26
Example
The example below only showcases purego use for macOS and Linux. The other platforms require special handling which can be seen in the complete example at examples/libc which supports FreeBSD and Windows.
package main
import (
"fmt"
"runtime"
"github.com/ebitengine/purego"
)
func getSystemLibrary() string {
switch runtime.GOOS {
case "darwin":
return "/usr/lib/libSystem.B.dylib"
case "linux":
return "libc.so.6"
default:
panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS))
}
}
func main() {
libc, err := purego.Dlopen(getSystemLibrary(), purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
panic(err)
}
var puts func(string)
purego.RegisterLibFunc(&puts, libc, "puts")
puts("Calling C from Go without Cgo!")
}
Then to run: CGO_ENABLED=0 go run main.go
Questions
If you have questions about how to incorporate purego in your project or want to discuss how it works join the Discord!
External Code
Purego uses code that originates from the Go runtime. These files are under the BSD-3 License that can be found in the Go Source. This is a list of the copied files:
abi_*.hfrom packageruntime/cgowincallback.gofrom packageruntimezcallback_darwin_*.sfrom packageruntimeinternal/fakecgo/abi_*.hfrom packageruntime/cgointernal/fakecgo/asm_GOARCH.sfrom packageruntime/cgointernal/fakecgo/callbacks.gofrom packageruntime/cgointernal/fakecgo/iscgo.gofrom packageruntime/cgointernal/fakecgo/setenv.gofrom packageruntime/cgointernal/fakecgo/freebsd.gofrom packageruntime/cgointernal/fakecgo/netbsd.gofrom packageruntime/cgo
The internal/fakecgo/go_GOOS.go files were modified from runtime/cgo/gcc_GOOS_GOARCH.go.
The files abi_*.h and internal/fakecgo/abi_*.h are the same because Bazel does not support cross-package use of
#include so we need each one once per package. (cf. issue)