Repository navigation
fix(bbb-graphql-middleware): End the connection handler on a rejected connection init - #26617
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]>
When connectionInitHandler rejected a connection, ConnectionHandler closed it with the error and then went on as if it had been accepted: it counted it in ws_connection_accepted, registered it as a user connection and started the Hasura and gql-actions clients for it. Return right after closing a rejected connection. The test sends an init without a session token and checks that the handler ends without registering the connection, and that the browser was rejected at the init (param_missing) and not before it. Co-authored-by: Tiago Jacobs <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe PR adds test configuration for the middleware and makes the connection handler return after rejecting a connection initialization. It adds a WebSocket test for that rejection. It also changes error construction and log formatting in several clients, and cancels a rate-limiter timeout context after the wait returns. Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
✅ Automated tests have passed! |
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.
A real case that reaches it: a client that is offline when its meeting ends. When the network comes back, bbb-web no longer authorizes that session, the client shows its error screen and retries about every 10 seconds. In 180 seconds that produced 16 websocket connections, all rejected at their init, on both binaries.
On the base, each of those rejections is also counted as an accepted connection:
time ws_connection_accepted ws_connection_rejected
05:25:11 2 0
05:28:13 18 16
With this branch:
05:38:03 1 0
05:41:05 1 16
The handler also went on to start the per-connection clients. Across the 16 rejected connections on the base, the journal has 16 "starting hasura client" and 16 "starting gql-actions client", and the browser writer starts as well; with this branch there are none of them. No connection to Hasura is actually opened in either case: the upgrade count of the Hasura nginx and hasura_websocket_connections do not move during the 16 rejections. So on the base the cost is the goroutines and the wrong count, not traffic to Hasura.
One case that does not reach it, in case someone wonders: a tab left open when the meeting ends shows the session ended screen and does not reconnect, so it produces no rejected connection at all.
In a clean golang:1.27-bookworm container with only bbb-graphql-middleware, go build ./..., go vet ./... and go test -race -count=2 ./... pass on this branch.
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
On this base a connection rejected at init returns before ws_connection_accepted is counted (since bigbluebutton#26617), but a connection closed by the connection_init timeout is not followed by a return: after the 4408 close the handler goes on, and the connection was counted in ws_connection_accepted as well as in ws_connection_rejected. The outcome of the init is now recorded in one place, before the branch, and a rejected or timed-out connection is counted as rejected only. The handler's flow is unchanged. The tests drive connections through ConnectionHandler from a websocket client: one rejected at init (param_missing), and one that sends nothing until the init timeout, which is counted as accepted without this change. Co-authored-by: Tiago Jacobs <[email protected]>
What does this PR do?
When the middleware rejected a connection at its init, the connection handler did not stop there. The handler now returns right after closing a rejected connection. Nothing changes for accepted connections.
Closes Issue(s)
None.
Motivation
connectionInitHandlerrejects a connection whose init is missing a required header or fails the checks at connection time.ConnectionHandlerthen closed the connection with the error and went on as if it had been accepted: it counted it inws_connection_accepted, registered it as a user connection and started the Hasura and gql-actions clients for it.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:The new test in
internal/websrv/connectionInitRejection_test.gosends an init without a required header and checks that the handler ends without registering the connection, and that the client was rejected at its init (param_missing) and not before it.More
Depends on #26615: this branch is built on it, because its test runs in
internal/websrv, whose tests needconfig/testconfigto run without an installed configuration. Until #26615 is merged, this PR also shows its two commits; the change here is the last commit. Docs not affected.