Repository navigation
[API-292] Adds back comms websocket support - #349
Conversation
raymondjacobson
left a comment
There was a problem hiding this comment.
this is awesome!
the ws impl could maybe use tests but not blocking for sure
| return nil, "", 0, err | ||
| } | ||
|
|
||
| app.commsRpcProcessor.SetPubkeyForUser(int32(userId), pubkey) |
| // Discard payload if any; we only care about keeping the socket healthy. | ||
| switch mt { | ||
| case websocket.TextMessage, websocket.BinaryMessage: | ||
| // Efficiently drain without allocating: |
There was a problem hiding this comment.
Not my idea lol. But I like it.
| }{ | ||
| rpcJson, | ||
| Metadata{ | ||
| Timestamp: timestamp.Format(time.RFC3339Nano), |
There was a problem hiding this comment.
Taken from existing implementation: https://github.com/AudiusProject/audius-protocol/blob/49d271631bcc6b3528a48d6d377cbfb6e53c6459/comms/discovery/rpcz/websocket.go#L77
It maps to an ISO timestamp with nanosecond accuracy (🙄 ). I am not sure if we break clients by changing it.
| default: | ||
| // If we get here, the client buffer is full (too slow in processing) | ||
| // and we will drop them for now. They can re-connect if needed. | ||
| m.logger.Info("ws buffer full; dropping client", |
There was a problem hiding this comment.
the client also keeps trying to reconnect right?
There was a problem hiding this comment.
Yes, assuming it has good network and is actually running (app wasn't closed/backgrounded, browser tab wasn't closed, etc) it will try to re-connect if we drop it.
Does bring up an interesting possibility though:
- We push 128 messages into a queue and aren't able to deliver
- Client gets disconnected
- Client re-connects and we push it the most recent messages we have for it, which might not include all of the 128 that it didn't receive.
That would be a strange experience where you are missing some chat messages. Technically I think that wouldn't happen in the existing comms implementation assuming the client eventually processed all of the 128 messages sitting in the queue. But I also think the sort of one-at-a-time nature of the existing implementation might degrade well before that point.
…934) ## Summary Bumps `github.com/OpenAudio/go-openaudio` and `.../pkg/etl` from `e8586ac` (#933) to **`bda0b8b`**. **Primary:** go-openaudio **#350** — - persists `developer_apps.image_url` (previously dropped; 271 prod apps have it), gated by the legacy `is_fqdn` check; - rune-counts the comment `video_url` and oauth `redirect_uri` length caps (byte-vs-rune over-strictness, same class as the name/bio fix). **Also carried** (main advanced past the baseline): - #349 — let a collaborator leave a track after accepting (reuses the `track_collaborators` table). - #351 — accept any genre string up to 100 chars (relaxes the genre allowlist). `core-indexer` runs this vendored image, so the bump is required to ship the fixes. ## Changes - `go.mod` / `go.sum`: both go-openaudio modules → `v1.3.1-0.20260609040102-bda0b8b592f5` ## Deploy note — no migration Latest ETL migration stays **0033** (#349 reuses the existing `track_collaborators` table). Everything here is code-only — no schema change, no special rollout. ## Test plan - [x] `go mod tidy` — only go.mod/go.sum changed - [x] `go build ./...` passes - [x] resolved module contains the image_url fix (`validatedAppImageURL`); migration unchanged (0033) - [ ] Post-deploy: set a dev-app icon and a long multibyte comment video on the test account → both persist 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
## Summary Audit of feature flags and env toggles in the API. Only one met the bar for removal. **Removed** - `skipAuthCheck` env var (`api/server.go`). When set to true, it turned off `isAuthorizedRequest` entirely, and production code read it from the environment. Nothing in this repo, compose, or k8s sets it. Every test that needs it sets `app.skipAuthCheck = true` on the struct, which still works. Added in #151 (2025-06) and never used through the env since. This cuts a dead toggle and an auth bypass at the same time. **Audited and kept (needs a decision from someone with prod access)** - `commsMessagePush`: defaults on since #349 (2025-09). The env override only turns it off. `server_test.go` depends on it to keep the websocket manager and pg-notify listeners out of the shared test app, so it works as a test seam. I couldn't confirm prod doesn't set `commsMessagePush=false`; if it doesn't, the env parse can go, but the struct field should stay for tests. - `coreBlockStreamEnabled`: defaults off and arrived in #941 (2026-06, ~5 months ago). I couldn't see the prod env (no RBAC on deployments/configmaps). If prod has it on, inline it; if it was never turned on, consider deleting the gRPC stream path. - `newChainQueueEnabled` / `newChainFlushEnabled` / `newChainInsecureSkipVerify` / `etlStartingBlockHeight` / `etlEndingBlockHeight` / `PlayRoutingHosts`: the genesis migration is still in progress (see `cmd/genesis-writer/ROLLOUT.md`). Not stale yet; remove them at cutover. ## Test plan - [x] `go build ./...` and `go vet ./api/` - [ ] `go test ./api/...` (couldn't run locally because Docker/test DB was down; CI covers it) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The original comms server would push a websocket message out as part of processing the rpc call. Since we will have multiple read replica servers and only one of them will be writing, that approach doesn't work.
So new plan!
See previous DN implementation of websocket connections here: https://github.com/AudiusProject/audius-protocol/blob/49d271631bcc6b3528a48d6d377cbfb6e53c6459/comms/discovery/rpcz/websocket.go#L29
Some notes:
.UTC()calls. While this is functionally equivalent on production servers where the machine timezone matches the DB, it is necessary for running locally without a lot of weird bugs and test failures. Long term fix is to convert the columns towith timezoneso that they are parsed into the correct "instant" no matter what the current machine timezone is.TODO:
Needs a lot of testing to make sure websockets are stable and all message types propagate correctly.
I also just noticed that I'm not pushing blasts and need to handle that correctly.
About the websocket implementation:
gobwas/wsused a pattern of "hijacking" the connection and returning from the handler, then later calling Close(). All of the fiber libraries use a pattern where the handler you provide for upgrading the connection is supposed to block in a read/write loop until you're ready to close the connection. Otherwise clients connect and then immediately disconnect. You also have to handle ping/pong messages and update write timeouts etc. So I started from scratch / generated implementation and tweaked it from there. The new flow is:The differences/improvements are: