Commit 2ca5ffc
authored
chore: simplify and modernize for Go 1.27 (#2627)
Follow-up to the Go 1.27 upgrade in a411024, applying what the new
release makes available.
## Modernizers
`go fix` gained `slicesbackward`, `embedlit` and `unsafefuncs`, and
renamed `waitgroup` to `waitgroupgo`. Applied across both modules, with
two exceptions:
- The extgen parsers are left alone: `embedlit` rewrites their composite
literals into a shape that reads worse than the original.
- `go fix` skips files that import `"C"`, so the root package never got
the transformations applied everywhere else. Those are done by hand in a
separate commit.
## Standard library
- `splitRemoteAddr` uses `strings.CutLast`, new in 1.27. Its not-found
return is exactly what the old `else` branch assigned, so the branch
disappears.
- The manual `unsafe.Pointer`/`uintptr` arithmetic in `types.go` and
`frankenphp.go` becomes `unsafe.Add`. The old form is only valid inside
a single expression and silently breaks if a later refactor splits the
line.
- `errors.As` becomes `errors.AsType`, dropping the throwaway target
values.
- Eleven copies of the register-or-panic block in `metrics.go` collapse
into one `mustRegister` helper.
## Tests
`internal/state` moves to `testing/synctest`. `synctest.Wait` returns
once every subscriber goroutine is durably blocked, so the subscriber
count is exact rather than polled for up to a second. This also makes
the `WaitForStateWithTimeout` give-up path worth covering, since the
bubble's fake clock fires its one second timeout instantly.
The other timing tests stay as they are. `regularRequestChan` is a
package global that live PHP thread goroutines receive from, so a
bubbled sender can have its send stolen by an out-of-bubble thread, and
PHP threads are C threads, which never count as durably blocked.
Bubbling them would buy flakiness, not determinism.
A new test uses the `goroutineleak` profile, GA in 1.27, to catch a
thread, scaling ticker or watcher goroutine that outlives `Shutdown`
with nothing left to wake it. Currently reports zero leaks across a full
`Init`/`Shutdown` cycle.
`/debug/pprof/goroutineleak` needs no code to expose:
`net/http/pprof.Index` dispatches profiles by name, so it is already
live on the admin endpoint. Verified against a running server. It
reports one leaked goroutine there, but the same one appears with no
`php_server` configured at all, so it is Caddy/runtime baseline rather
than ours.
## Drive-by
`internal/state` had a bare `import "C"` with no C preamble and no calls
into C, which forced a pure Go package through cgo. Removed.
## No action needed
`encoding/json/v2` backing `encoding/json` and the size-specialized
allocator are both in the 1.27 baseline and active automatically. The
stricter jsonv2 defaults ship only with an explicit `encoding/json/v2`
import, so v1 semantics are unchanged: duplicate keys still accepted,
invalid UTF-8 still replaced rather than rejected.1 parent a411024 commit 2ca5ffc
24 files changed
Lines changed: 164 additions & 128 deletions
File tree
- caddy
- internal
- extgen
- state
- watcher
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
903 | 903 | | |
904 | 904 | | |
905 | 905 | | |
906 | | - | |
| 906 | + | |
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
| |||
1830 | 1830 | | |
1831 | 1831 | | |
1832 | 1832 | | |
1833 | | - | |
| 1833 | + | |
1834 | 1834 | | |
1835 | 1835 | | |
1836 | 1836 | | |
| |||
2138 | 2138 | | |
2139 | 2139 | | |
2140 | 2140 | | |
2141 | | - | |
| 2141 | + | |
2142 | 2142 | | |
2143 | 2143 | | |
2144 | 2144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
| 142 | + | |
144 | 143 | | |
145 | 144 | | |
146 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 366 | + | |
| 367 | + | |
372 | 368 | | |
373 | 369 | | |
374 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | | - | |
| 62 | + | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
240 | | - | |
| 239 | + | |
| 240 | + | |
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments