Repository navigation
fix(bbb-graphql-middleware): Fix the findings of go vet and run the tests without an installed config - #26615
Conversation
go vet reports printf-style calls whose format does not match its arguments: Debug and Errorf used as if the other were the f variant, an error built from a non-constant format string, and a context whose cancel function was discarded in the writer's query rate limiter wait. Use the matching logrus call, errors.New for the plain message, and cancel the rate limiter context as soon as the wait returns. Co-authored-by: Tiago Jacobs <[email protected]>
Some packages read the configuration when they are initialized, from /usr/share/bbb-graphql-middleware/config.yml and an override in /etc/bigbluebutton, so a test binary of such a package failed on a machine without the middleware installed: go test ./... already failed in internal/websrv. The config/testconfig package points the configuration at the repository's config/config.yml and at an override path that does not exist; a package whose tests load the configuration imports it from a test file. Go initializes it right after config, before any internal package. Co-authored-by: Tiago Jacobs <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe changes add a test-only package that sets the repository’s default configuration path and a nonexistent override path. The websrv tests blank-import the package. Middleware updates construct unauthorized errors with Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
✅ Automated tests have passed! |
paultrudel
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me. I ran it on a machine without the middleware installed, with Go 1.27.0:
- base (e2dab6e):
go vet ./...reports the six findings.go test -race -count=2 ./...fails ininternal/websrvon the missing/usr/share/bbb-graphql-middleware/config.yml, and also in five other packages, because the printf check thatgo testruns itself fails on the same calls. - head (d25b4ae):
go build,go vetandgo test -race -count=2 ./...all pass.
The vet fixes are correct as they are. errors.New(message) also stops a % in the akka-apps message from being read as a format directive, and the rate limiter's context is now cancelled right after Wait returns.
None of the points below blocks the merge:
testconfigrelies on the source path recorded at build time.runtime.Caller(0)returns a module-relative path when the tests are built with-trimpath, sogo test -trimpath ./internal/websrv/fails again withError while loading config file (bbb-graphql-middleware/config/config.yml). I reproduced it. Nothing in the repo uses-trimpath, so this is about robustness only. Walking up fromos.Getwd()to the directory that holdsgo.modwould avoid it (go testruns in the package directory). At the least, checking theokresult would give a clear error instead of a path relative to..- The redirect depends on init order. The package comment explains it well, and the order follows the spec. Still, a later package that reads the configuration at init and whose import path sorts before
config/testconfig(anything undercmd/, or aconfig/schema) would read the installed config first, andGetConfig'ssync.Oncewould keep that result. Making the remaining package-level reads lazy, asrediscli.goalready does, would remove that dependency. That could fit one of the middleware PRs that build on this one. - Optional: since
config/testconfigis an ordinary package, a stray import from non-test code would redirect the server's config. Aif !testing.Testing() { panic(...) }in itsinitwould rule that out. - Tiny: the
Debugfatinternal/bbb_web/client.go:94logs through the globallog, so those lines lack the connection fields thatloggeradds to the lines around them.
No CI job runs go vet or go test for the middleware yet. Is that coming in one of the follow-up PRs?
TiagoJacobs
left a comment
There was a problem hiding this comment.
Reviewed and tested on a 4.0 server built from source at v4.0.x-develop commit 3098b16087, with only the middleware swapped between that commit and this branch.
Where the formatting defect shows. internal/bbb_web/client.go:94 runs on every authorized connection init, so once when a user joins and once on every websocket reconnection, five lines per join. On the base the format verbs are not applied and the key and the value come out glued together:
"msg": "%s: %s\nx-moderatorfalse"
"msg": "%s: %s\nx-userid<redacted>"
With this branch:
"msg": "x-moderator: false"
"msg": "x-userid: <redacted>"
Where the discarded cancel shows. Every subscribe builds a 30 s timeout context in internal/hasura/conn/writer/writer.go whose cancel function is dropped, so its timer and its entry in the parent context stay alive until the deadline passes or the Hasura connection is cancelled. In a trace log of 15 browser connections on the base, each connection sent 31 to 56 subscribe frames (median 35), and a single Hasura reconnection resent up to 26 of them, so one connection can hold tens of those timers at a time. With this branch the cancel runs as soon as the wait returns.
And the checks themselves, in a clean golang:1.27-bookworm container with only bbb-graphql-middleware, at the same commit of v4.0.x-develop:
go vet ./... exits 1, with the six findings listed in the PR
go test ./... fails in six packages: five do not build, because go test runs vet,
and internal/websrv fails on the missing configuration file
With this branch, go build ./..., go vet ./... and go test -race -count=2 ./... all pass in the same container.
Brings v4.0.x-develop to 932c31d: the merged bigbluebutton#26631 and the fixes that followed it on 4.0 (bigbluebutton#26642 and bigbluebutton#26634 for the API conformance Tier 1 stack, bigbluebutton#26641 for the presentation conversion tests, bigbluebutton#26636 and bigbluebutton#26617 for the middleware limits, bigbluebutton#26581 for failed uploads), plus bigbluebutton#26583, bigbluebutton#26548 and bigbluebutton#26615. Resolutions: - api-conformance env/tier1/copies.sha256: each hash matches the merged file. preinst is 4.1's own (0413ab4), so 4.1's line; start-template has 4.0.3's change on both lines now, so 4.0's line. - docs new-features.md: 4.1's file, unchanged. # Conflicts: # bigbluebutton-tests/api-conformance/env/tier1/copies.sha256 # docs/docs/new-features.md
What does this PR do?
Two things kept the middleware's own checks from passing in a clean checkout:
go vet ./...reported findings, andgo test ./...failed ininternal/websrvon a machine without the middleware installed. This PR fixes both.errors.New, the two log calls useDebugfandError, and the rate limiter's context is cancelled as soon as the wait returns. The debug log lines now show their values.config/testconfig, points the configuration at the repository'sconfig/config.ymland at an override path that does not exist. A package whose tests load the configuration imports it from a test file;internal/websrvdoes so here. Its comment explains why it is initialized before the packages that read the configuration. Production code does not import it.Closes Issue(s)
None.
Motivation
go vet ./...reported printf-style calls whose format did not match their arguments, and a discarded cancel function:internal/akka_apps/client.go: an error built withfmt.Errorffrom a non-constant message;internal/bbb_web/client.goandinternal/hasura/conn/reader/reader.go: logrusDebugcalled with a format string and arguments, so the values were not formatted;internal/gql_actions/client.goandinternal/hasura/conn/writer/writer.go: logrusErrorfcalled with a non-constant message;internal/hasura/conn/writer/writer.go: the cancel function of the query rate limiter's timeout context was discarded./usr/share/bbb-graphql-middleware/config.ymland an override in/etc/bigbluebutton. A test binary of such a package fails before any test runs on a machine without the middleware installed, sogo test ./...failed ininternal/websrv.How to test
In a clean checkout (for example a
golang:1.27-bookwormcontainer with onlybbb-graphql-middleware, without/usr/share/bbb-graphql-middlewareand without/etc/bigbluebutton), run inbbb-graphql-middleware:go vet ./...reports the findings above andgo test ./...fails ininternal/websrv.go testininternal/websrvon a machine without the installed configuration, as the base does; the second commit fixes that.More
Docs not affected. The middleware PRs that follow are built on this one.