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

fix: fix field alignment to avoid panics on 32bit OSes #44

Merged
merged 7 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.19.x
- name: Lint
Expand All @@ -19,24 +19,24 @@ jobs:
test:
strategy:
matrix:
platform:
- ubuntu-latest
go:
- 1.18.x
- 1.19.x
include:
- platform: macos-latest
go: 1.19.x
- platform: windows-latest
go: 1.19.x
platform: [ ubuntu-latest, windows-latest, macos-latest ]
version: [ v1.19.x ]
goarch: [ amd64, '386' ]
exclude:
- platform: macos-latest
goarch: '386'
- platform: windows-latest
goarch: '386'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks!

We may want to reduce the matrix a bit to a single 32 bit runner in the future, assuming we can prove the effective coverage is the same. As someone who's worked with 32 bit arch's more than me, do you foresee any problems with only validating those arch's on a single platform and Go version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I didn't also add 32-bit ARM as well is that it's a huge pain to do (without Docker) in GitHub Actions, because the GitHub-hosted runners are all AMD64 currently (ARM64 is coming this fall maybe?).

Another option is to use a self-hosted runner, and I happen to be deep in that rabbit-hole right now (hairyhenderson/gomplate#2126) and it's going about as well as you'd expect (i.e. not at all well).

For this particular class of bug any 32-bit platform will generally do, but there are other classes of bugs that can crop up only on 32-bit ARM CPUs. Somewhat ironically it's extremely rare to run into 32-bit Intel systems except for niche embedded use-cases, but it's still quite common to run into 32-bit ARM given the massive proliferation of older Raspberry Pi-type systems and routers strewn across the IoT landscape.

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
go-version: ${{ matrix.version }}
architecture: ${{ matrix.goarch }}
- name: Test
run: make test
env:
GOARCH: ${{ matrix.goarch }}
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERAGE_VERSION: 1.19
COVERAGE_VERSION: '1.19'
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
linters-settings:
govet:
enable:
- fieldalignment

linters:
enable:
# Default linters, plus these:
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BROWSERTEST_VERSION = v0.7
LINT_VERSION = 1.50.1
GO_BIN = $(shell printf '%s/bin' "$$(go env GOPATH)")
SHELL = bash
ENABLE_RACE = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Looks like this var is now unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ good catch - that can be deleted


.PHONY: all
all: lint test
Expand All @@ -12,7 +13,7 @@ lint-deps:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GO_BIN}" v${LINT_VERSION}; \
fi
@if ! which jsguard >/dev/null; then \
go install github.com/hack-pad/safejs/jsguard/cmd/jsguard; \
go install github.com/hack-pad/safejs/jsguard/cmd/jsguard@latest; \
fi

.PHONY: lint
Expand All @@ -31,14 +32,25 @@ test-deps:
fi
@go install github.com/mattn/[email protected]

# only use the race detector on supported architectures
race_goarches := 'amd64' 'arm64'
ifeq (,$(findstring '$(GOARCH)',$(race_goarches)))
TEST_ARGS=
export CGO_ENABLED=0
else
TEST_ARGS=-race
# the race detector needs cgo (at least on Linux and Windows, and macOS until Go 1.20)
export CGO_ENABLED=1
endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, bummer about race not being supported, this looks like a reasonable setup. Thank you for handling all of that. This must've been a pain wrangling with CI for so long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was already in the midst doing a similar thing for gomplate so it at least wasn't a new kind of pain 😅

It probably isn't always true, but races tend to happen in the same way on all platforms, so I wouldn't be too worried here.


.PHONY: test
test: test-deps
go test . # Run library-level checks first, for more helpful build tag failure messages.
go test -race -coverprofile=native-cover.out ./...
go test $(TEST_ARGS) -coverprofile=native-cover.out ./...
if [[ "$$CI" != true || $$(uname -s) == Linux ]]; then \
set -ex; \
GOOS=js GOARCH=wasm go test -coverprofile=js-cover.out -covermode=atomic ./...; \
cd examples && go test -race ./...; \
cd examples && go test $(TEST_ARGS) ./...; \
fi
{ echo 'mode: atomic'; cat *-cover.out | grep -v '^mode:'; } > cover.out && rm *-cover.out
go tool cover -func cover.out | grep total:
Expand Down
5 changes: 2 additions & 3 deletions cache/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ type ReadOnlyFS struct {
sourceFS hackpadfs.FS
cacheFS writableFS
cacheInfo sync.Map

pathlock pathlock.Mutex
options ReadOnlyOptions
options ReadOnlyOptions
pathlock pathlock.Mutex
}

// ReadOnlyOptions contain options for creating a ReadOnlyFS
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type PathError = fs.PathError
//
// NOTE: Is not identical to os.LinkError to avoid importing "os". Still resolves errors.Is() calls correctly.
type LinkError struct {
Err error
Op string
Old string
New string
Err error
}

func (e *LinkError) Error() string {
Expand Down
46 changes: 2 additions & 44 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hack-pad/hackpadfs/examples

go 1.18
go 1.19

require (
github.com/hack-pad/hackpadfs v0.1.1
Expand All @@ -18,11 +18,7 @@ require (
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/azure-storage-blob-go v0.15.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/Shopify/sarama v1.37.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/alecthomas/participle v0.7.1 // indirect
github.com/apache/thrift v0.17.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
Expand All @@ -32,7 +28,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.4.0 // indirect
github.com/bits-and-blooms/bloom/v3 v3.3.1 // indirect
github.com/briandowns/spinner v1.16.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/bubbles v0.14.0 // indirect
Expand All @@ -56,17 +51,14 @@ require (
github.com/eapache/queue v1.1.0 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/elastic/go-elasticsearch/v7 v7.17.7 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/fraugster/parquet-go v0.12.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.5.3 // indirect
github.com/georgysavva/scany v0.2.7 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect
github.com/go-ldap/ldap/v3 v3.4.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
Expand All @@ -79,25 +71,19 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.4.3 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20221219190121-3cb0bae90811 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
Expand Down Expand Up @@ -139,26 +125,19 @@ require (
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/minio/argon2 v1.0.0 // indirect
github.com/minio/cli v1.24.2 // indirect
github.com/minio/colorjson v1.0.4 // indirect
github.com/minio/console v0.23.0 // indirect
github.com/minio/csvparser v1.0.0 // indirect
github.com/minio/direct-csi v1.3.5-0.20210601185811-f7776f7961bf // indirect
github.com/minio/dperf v0.4.2 // indirect
github.com/minio/filepath v1.0.0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/kes v0.22.2 // indirect
github.com/minio/madmin-go v1.7.5 // indirect
github.com/minio/madmin-go/v2 v2.0.7 // indirect
github.com/minio/mc v0.0.0-20230123151138-468fc49d0fc1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/mux v1.8.2 // indirect
github.com/minio/operator v0.0.0-20220902184351-21e4073132b0 // indirect
github.com/minio/operator/logsearchapi v0.0.0-20211011212245-31460bbbc4b7 // indirect
github.com/minio/parquet-go v1.1.0 // indirect
github.com/minio/pkg v1.6.0 // indirect
github.com/minio/selfupdate v0.5.0 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
Expand Down Expand Up @@ -189,9 +168,7 @@ require (
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.6.0 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
Expand All @@ -211,23 +188,19 @@ require (
github.com/secure-io/sio-go v0.3.1 // indirect
github.com/shirou/gopsutil/v3 v3.22.11 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/streadway/amqp v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.3 // indirect
github.com/tinylib/msgp v1.1.7 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/unrolled/secure v1.13.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.etcd.io/etcd/api/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/v3 v3.5.6 // indirect
Expand All @@ -253,25 +226,10 @@ require (
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/h2non/filetype.v1 v1.0.5 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect
gopkg.in/jcmturner/dnsutils.v1 v1.0.1 // indirect
gopkg.in/jcmturner/gokrb5.v7 v7.5.0 // indirect
gopkg.in/jcmturner/rpc.v1 v1.1.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.1 // indirect
k8s.io/apimachinery v0.26.1 // indirect
k8s.io/client-go v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20230115233650-391b47cb4029 // indirect
maze.io/x/duration v0.0.0-20160924141736-faac084b6075 // indirect
sigs.k8s.io/controller-runtime v0.11.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/hack-pad/hackpadfs => ../
Loading