5 Commits
Author SHA1 Message Date
Mathias Fredriksson 856a8684cb fix: prevent channel shutdown send races (#29658)
Workspace update subscriptions and VPN tunnels could close a channel
while another goroutine was still sending on it, panicking with `send on
closed channel`. VPN senders could also block forever once nothing read
the channel.

- `coderd`: `sub.Close` no longer closes the updates channel, so a
pubsub callback still running cannot send on a closed channel.
- `vpn`: after Stop, the tunnel no longer closes the shared send
channel. The writer exits after writing the Stop response, so Stop is
the final frame, and its exit is what ends the senders below.
- `vpn`: a speaker send context ends when the speaker is canceled or the
writer exits, for example on a write error. RPCs, RPC replies, updates
and logs wait on it, so they return instead of blocking on a channel
nothing reads. Before, an update holding the updater mutex could block a
Stop the tunnel had already read. The updater context derives from it,
so the updater also stops after Stop when Start never succeeded.
- `vpn`: RPC response channels are buffered, so delivering a response no
longer deadlocks against a caller canceled at the same moment. That
deadlock exists on main for a canceled caller context, and the send
context adds a cancellation at shutdown. A response received before EOF
or writer exit is returned instead of an error.

<details>
<summary>Decisions and regression evidence</summary>

- Nothing observes the subscription channel closing: its only reader,
`WorkspaceUpdates` in `tailnet/service.go`, also stops on its stream
context and calls `Close` itself.
- The tunnel does not cancel its speaker after Stop. Senders return once
the writer has finished the Stop response rather than when it is handed
over, and a request the manager sends after Stop stays parked until
`Tunnel.Close`, as on main.
- `updater.stop` is unchanged: it cancels after closing the conn, so
logs the conn emits while closing reach the manager (the tunnel is the
only log sink with `UseAsLogger` on macOS).
`TestTunnel_StopForwardsCloseLogs` guards that ordering.
- RPCs wait on the send context directly instead of relying on
`recvLoopDone`. The receive loop cannot exit while it is handing a
request to a busy `requestLoop`, and closing a blocking file descriptor
may not interrupt its read. `recvFromSerdes` still delivers requests
after the writer exits, so a Stop it has already read is not dropped.
When only the writer has exited, RPCs return `io.ErrUnexpectedEOF`, as
for EOF. Every RPC return removes its response channel, so RPCs that
fail after the writer exits do not accumulate entries.
- Against main's production code:
- `TestWorkspaceUpdatesClose/{QueryInFlight,CallbackAfterClose}` and
`TestTunnel_StopConcurrentSenders` panic with `send on closed channel`.
  - `TestSpeaker_ResponseDuringCancellation` deadlocks.
  - `TestSerdes_StopClosesAfterResponse` receives a frame after Stop.
- `TestTunnel_StopAfterWriterExits` and
`TestSpeaker_RPCAfterWriterExits` stay blocked after the writer exits.
- `TestSpeaker_ResponseBeforeEOF`,
`TestSpeaker_ResponseBeforeWriterExits` and
`TestTunnel_StopForwardsCloseLogs` pass on main. They guard ordering the
fix depends on: each fails when that ordering is changed or the matching
part of the fix is removed.
- The regression tests pass 50 runs with `-race`. The `vpn` and
`tailnet` race suites pass.

</details>

> This PR was created with the help of Coder Agents for @mafredri and
will be reviewed by a human.
2026-11-26 10:53:41 +02:00
ケイラ f670bc31f5 chore: update testutil chan helpers (#17408) 2025-04-16 10:37:09 -06:00
Jon AyersandClaude 17ddee05e5 chore: update golang to 1.24.1 (#17035)
- Update go.mod to use Go 1.24.1
- Update GitHub Actions setup-go action to use Go 1.24.1
- Fix linting issues with golangci-lint by:
  - Updating to golangci-lint v1.57.1 (more compatible with Go 1.24.1)

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <claude@anthropic.com>
2025-03-26 01:56:39 -05:00
Spike Curtis 5861e516b9 chore: add standard test logger ignoring db canceled (#15556)
Refactors our use of `slogtest` to instantiate a "standard logger" across most of our tests.  This standard logger incorporates https://github.com/coder/slog/pull/217 to also ignore database query canceled errors by default, which are a source of low-severity flakes.

Any test that has set non-default `slogtest.Options` is left alone. In particular, `coderdtest` defaults to ignoring all errors. We might consider revisiting that decision now that we have better tools to target the really common flaky Error logs on shutdown.
2024-11-18 14:09:22 +04:00
Ethan b1298a3c1e feat: add WorkspaceUpdates tailnet RPC (#14847)
Closes #14716
Closes #14717

Adds a new user-scoped tailnet API endpoint (`api/v2/tailnet`) with a new RPC stream for receiving updates on workspaces owned by a specific user, as defined in #14716. 

When a stream is started, the `WorkspaceUpdatesProvider` will begin listening on the user-scoped pubsub events implemented in #14964. When a relevant event type is seen (such as a workspace state transition), the provider will query the DB for all the workspaces (and agents) owned by the user. This gets compared against the result of the previous query to produce a set of workspace updates. 

Workspace updates can be requested for any user ID, however only workspaces the authorised user is permitted to `ActionRead` will have their updates streamed.
Opening a tunnel to an agent requires that the user can perform `ActionSSH` against the workspace containing it.
2024-11-01 14:53:53 +11:00