Skip to content

Enable CGO on sg binary releases to fix "too many open files" bug

Administrator requested to merge mrn/testing-sg-cross-compiling into main

Created by: mrnugget

This fixes #28354 (closed) by using CGO_ENABLED=1 when building sg binaries. We didn't do that in the past because we didn't know it was that easy to run on macos-latest in GitHub workflows.

And using CGO_ENABLED=0 caused the file-watching library we're using - github.com/rjeczalik/notify - to fallback to kqueue to watch files on macOS. That in turn is not performant when watching files in large folders. It seems to open/stat every file in our repository which then lead to a "too many open files" error.

(You can see this in action if you compile sg with CGO_ENABLED=0 go build -o sg . and then run sudo dtruss ./sg run github-proxy on macOS. You'll see ton of open and stat syscalls.)

With CGO enabled though, notify uses FSEvents on macOS which handles our repository much better.

And that also explains why building sg locally fixed the issue: locally we didn't turn CGO off.

Merge request reports

Loading