Skip to content

Commit 47de322

Browse files
committed
Update to go 1.21
Use `atomic.Bool` stdlib instead of including our own. Include `tools\mkwinsyscall` updates from go-winio/283 to switch to `syscallN`. Note: removed `// TODO` about `print`/`ln`, since the latter adds spaces between args when printing, which is undesired. Also update CI to run steps on windows-2022 instead of windows-2019, similar to our hcsshim CI. Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent 008bc6e commit 47de322

20 files changed

+140
-227
lines changed

Diff for: .github/workflows/ci.yml

+19-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ on:
66
env:
77
GO_VERSION: "oldstable"
88
GOTESTSUM_VERSION: "latest"
9+
GOLANGCILINT_VERSION: "latest"
910

1011
jobs:
1112
lint:
1213
name: Lint
13-
runs-on: windows-2019
14+
runs-on: windows-2022
1415
steps:
1516
- name: Checkout
1617
uses: actions/checkout@v4
@@ -24,9 +25,9 @@ jobs:
2425
cache: false
2526

2627
- name: Run golangci-lint
27-
uses: golangci/golangci-lint-action@v3
28+
uses: golangci/golangci-lint-action@v4
2829
with:
29-
version: v1.53
30+
version: ${{ env.GOLANGCILINT_VERSION }}
3031
args: >-
3132
--verbose
3233
--timeout=5m
@@ -37,7 +38,7 @@ jobs:
3738
3839
go-generate:
3940
name: Go Generate
40-
runs-on: windows-2019
41+
runs-on: windows-2022
4142
steps:
4243
- name: Checkout
4344
uses: actions/checkout@v4
@@ -103,7 +104,19 @@ jobs:
103104
run: go install gotest.tools/gotestsum@${{ env.GOTESTSUM_VERSION }}
104105

105106
- name: Test repo
106-
run: gotestsum --format standard-verbose --debug -- -gcflags=all=-d=checkptr -race -v ./...
107+
shell: pwsh
108+
run: |
109+
# `go test -race` requires mingw on windows, and there is some weirdness on windows 2019
110+
# which causes tests to fail with `"exit status 0xc0000139"`.
111+
# Even trying to update mingw with choco still fails.
112+
#
113+
# see: https://go.dev/doc/articles/race_detector#Requirements
114+
115+
if ( '${{ matrix.os }}' -ne 'windows-2019' ) {
116+
$race = '-race'
117+
}
118+
119+
gotestsum --format standard-verbose --debug -- -gcflags=all=-d=checkptr $race -v ./...
107120
108121
# !NOTE:
109122
# Fuzzing cannot be run across multiple packages, (ie, `go -fuzz "^Fuzz" ./...` fails).
@@ -115,7 +128,7 @@ jobs:
115128
name: Build Repo
116129
needs:
117130
- test
118-
runs-on: "windows-2019"
131+
runs-on: "windows-2022"
119132
steps:
120133
- name: Checkout
121134
uses: actions/checkout@v4

Diff for: .golangci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
run:
2-
skip-dirs:
3-
- pkg/etw/sample
4-
51
linters:
62
enable:
73
# style
@@ -24,6 +20,9 @@ linters:
2420
- unparam # unused function params
2521

2622
issues:
23+
exclude-dirs:
24+
- pkg/etw/sample
25+
2726
exclude-rules:
2827
# err is very often shadowed in nested scopes
2928
- linters:
@@ -70,9 +69,7 @@ linters-settings:
7069
# struct order is often for Win32 compat
7170
# also, ignore pointer bytes/GC issues for now until performance becomes an issue
7271
- fieldalignment
73-
check-shadowing: true
7472
nolintlint:
75-
allow-leading-space: false
7673
require-explanation: true
7774
require-specific: true
7875
revive:
@@ -112,6 +109,9 @@ linters-settings:
112109
- name: line-length-limit
113110
arguments:
114111
- 140
112+
# - name: unchecked-type-assertion
113+
# arguments:
114+
# - acceptIgnoredAssertionResult: true
115115
- name: var-naming
116116
arguments:
117117
- []

Diff for: file.go

+12-30
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ import (
2121
//sys setFileCompletionNotificationModes(h windows.Handle, flags uint8) (err error) = SetFileCompletionNotificationModes
2222
//sys wsaGetOverlappedResult(h windows.Handle, o *windows.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) = ws2_32.WSAGetOverlappedResult
2323

24-
//todo (go1.19): switch to [atomic.Bool]
25-
26-
type atomicBool int32
27-
28-
func (b *atomicBool) isSet() bool { return atomic.LoadInt32((*int32)(b)) != 0 }
29-
func (b *atomicBool) setFalse() { atomic.StoreInt32((*int32)(b), 0) }
30-
func (b *atomicBool) setTrue() { atomic.StoreInt32((*int32)(b), 1) }
31-
32-
//revive:disable-next-line:predeclared Keep "new" to maintain consistency with "atomic" pkg
33-
func (b *atomicBool) swap(new bool) bool {
34-
var newInt int32
35-
if new {
36-
newInt = 1
37-
}
38-
return atomic.SwapInt32((*int32)(b), newInt) == 1
39-
}
40-
4124
var (
4225
ErrFileClosed = errors.New("file has already been closed")
4326
ErrTimeout = &timeoutError{}
@@ -81,7 +64,7 @@ type win32File struct {
8164
handle windows.Handle
8265
wg sync.WaitGroup
8366
wgLock sync.RWMutex
84-
closing atomicBool
67+
closing atomic.Bool
8568
socket bool
8669
readDeadline deadlineHandler
8770
writeDeadline deadlineHandler
@@ -92,7 +75,7 @@ type deadlineHandler struct {
9275
channel timeoutChan
9376
channelLock sync.RWMutex
9477
timer *time.Timer
95-
timedout atomicBool
78+
timedout atomic.Bool
9679
}
9780

9881
// makeWin32File makes a new win32File from an existing file handle.
@@ -131,7 +114,7 @@ func NewOpenFile(h windows.Handle) (io.ReadWriteCloser, error) {
131114
func (f *win32File) closeHandle() {
132115
f.wgLock.Lock()
133116
// Atomically set that we are closing, releasing the resources only once.
134-
if !f.closing.swap(true) {
117+
if !f.closing.Swap(true) {
135118
f.wgLock.Unlock()
136119
// cancel all IO and wait for it to complete
137120
_ = cancelIoEx(f.handle, nil)
@@ -152,14 +135,14 @@ func (f *win32File) Close() error {
152135

153136
// IsClosed checks if the file has been closed.
154137
func (f *win32File) IsClosed() bool {
155-
return f.closing.isSet()
138+
return f.closing.Load()
156139
}
157140

158141
// prepareIO prepares for a new IO operation.
159142
// The caller must call f.wg.Done() when the IO is finished, prior to Close() returning.
160143
func (f *win32File) prepareIO() (*ioOperation, error) {
161144
f.wgLock.RLock()
162-
if f.closing.isSet() {
145+
if f.closing.Load() {
163146
f.wgLock.RUnlock()
164147
return nil, ErrFileClosed
165148
}
@@ -193,7 +176,7 @@ func (f *win32File) asyncIO(c *ioOperation, d *deadlineHandler, bytes uint32, er
193176
return int(bytes), err
194177
}
195178

196-
if f.closing.isSet() {
179+
if f.closing.Load() {
197180
_ = cancelIoEx(f.handle, &c.o)
198181
}
199182

@@ -209,7 +192,7 @@ func (f *win32File) asyncIO(c *ioOperation, d *deadlineHandler, bytes uint32, er
209192
case r = <-c.ch:
210193
err = r.err
211194
if err == windows.ERROR_OPERATION_ABORTED { //nolint:errorlint // err is Errno
212-
if f.closing.isSet() {
195+
if f.closing.Load() {
213196
err = ErrFileClosed
214197
}
215198
} else if err != nil && f.socket {
@@ -242,7 +225,7 @@ func (f *win32File) Read(b []byte) (int, error) {
242225
}
243226
defer f.wg.Done()
244227

245-
if f.readDeadline.timedout.isSet() {
228+
if f.readDeadline.timedout.Load() {
246229
return 0, ErrTimeout
247230
}
248231

@@ -256,9 +239,8 @@ func (f *win32File) Read(b []byte) (int, error) {
256239
return 0, io.EOF
257240
} else if err == windows.ERROR_BROKEN_PIPE { //nolint:errorlint // err is Errno
258241
return 0, io.EOF
259-
} else {
260-
return n, err
261242
}
243+
return n, err
262244
}
263245

264246
// Write writes to a file handle.
@@ -269,7 +251,7 @@ func (f *win32File) Write(b []byte) (int, error) {
269251
}
270252
defer f.wg.Done()
271253

272-
if f.writeDeadline.timedout.isSet() {
254+
if f.writeDeadline.timedout.Load() {
273255
return 0, ErrTimeout
274256
}
275257

@@ -306,7 +288,7 @@ func (d *deadlineHandler) set(deadline time.Time) error {
306288
}
307289
d.timer = nil
308290
}
309-
d.timedout.setFalse()
291+
d.timedout.Store(false)
310292

311293
select {
312294
case <-d.channel:
@@ -321,7 +303,7 @@ func (d *deadlineHandler) set(deadline time.Time) error {
321303
}
322304

323305
timeoutIO := func() {
324-
d.timedout.setTrue()
306+
d.timedout.Store(true)
325307
close(d.channel)
326308
}
327309

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/Microsoft/go-winio
22

3-
go 1.17
3+
go 1.21
44

55
require (
66
github.com/sirupsen/logrus v1.9.3

Diff for: go.sum

-38
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,15 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs
88
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
99
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1010
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11-
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
12-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13-
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
14-
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
15-
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
16-
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
1711
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
1812
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
19-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
20-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
21-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
22-
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
23-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
24-
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
25-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
26-
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2813
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
2914
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
30-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
31-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3415
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
36-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3816
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
3917
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
41-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
42-
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
43-
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
44-
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
45-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
46-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
47-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
48-
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
49-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
50-
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
51-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
52-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
53-
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
54-
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
5518
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
5619
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
57-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5820
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5921
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
6022
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Diff for: hvsock_test.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ func clientServer(u testUtil) (cl, sv *HvsockConn, _ *HvsockAddr) {
5757
if err != nil {
5858
return fmt.Errorf("listener accept: %w", err)
5959
}
60-
sv = conn.(*HvsockConn)
60+
var ok bool
61+
sv, ok = conn.(*HvsockConn)
62+
if !ok {
63+
return fmt.Errorf("expected connection type %T; got %T", new(HvsockConn), conn)
64+
}
6165
if err := l.Close(); err != nil {
6266
return err
6367
}
@@ -109,7 +113,10 @@ func TestHvSockListenerAddresses(t *testing.T) {
109113
u := newUtil(t)
110114
l, addr := serverListen(u)
111115

112-
la := (l.Addr()).(*HvsockAddr)
116+
la, ok := (l.Addr()).(*HvsockAddr)
117+
if !ok {
118+
t.Fatalf("expected type %T; got %T", new(HvsockAddr), l.Addr())
119+
}
113120
u.Assert(*la == *addr, fmt.Sprintf("give: %v; want: %v", la, addr))
114121

115122
ra := rawHvsockAddr{}
@@ -123,10 +130,22 @@ func TestHvSockAddresses(t *testing.T) {
123130
u := newUtil(t)
124131
cl, sv, addr := clientServer(u)
125132

126-
sra := (sv.RemoteAddr()).(*HvsockAddr)
127-
sla := (sv.LocalAddr()).(*HvsockAddr)
128-
cra := (cl.RemoteAddr()).(*HvsockAddr)
129-
cla := (cl.LocalAddr()).(*HvsockAddr)
133+
sra, ok := (sv.RemoteAddr()).(*HvsockAddr)
134+
if !ok {
135+
t.Fatalf("expected type %T; got %T", new(HvsockAddr), sv.RemoteAddr())
136+
}
137+
sla, ok := (sv.LocalAddr()).(*HvsockAddr)
138+
if !ok {
139+
t.Fatalf("expected type %T; got %T", new(HvsockAddr), sv.LocalAddr())
140+
}
141+
cra, ok := (cl.RemoteAddr()).(*HvsockAddr)
142+
if !ok {
143+
t.Fatalf("expected type %T; got %T", new(HvsockAddr), cl.RemoteAddr())
144+
}
145+
cla, ok := (cl.LocalAddr()).(*HvsockAddr)
146+
if !ok {
147+
t.Fatalf("expected type %T; got %T", new(HvsockAddr), cl.LocalAddr())
148+
}
130149

131150
t.Run("Info", func(t *testing.T) {
132151
tests := []struct {
@@ -322,7 +341,10 @@ func TestHvSockCloseReadWriteListener(t *testing.T) {
322341
}
323342
defer c.Close()
324343

325-
hv := c.(*HvsockConn)
344+
hv, ok := c.(*HvsockConn)
345+
if !ok {
346+
t.Fatalf("expected type %T; got %T", new(HvsockConn), c)
347+
}
326348
//
327349
// test CloseWrite()
328350
//

Diff for: internal/computestorage/zsyscall_windows.go

+2-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)