Skip to content

Commit 8afca6c

Browse files
committed
fix: Add latency-check for DERP over HTTP(s)
This fixes scenarios where latency wasn't being reported if a connection had UDP entirely blocked.
1 parent 567e750 commit 8afca6c

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

coderd/coderd.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ func New(options *Options) *API {
165165
// other applications might not as well.
166166
r.Route("/%40{user}/{workspace_and_agent}/apps/{workspaceapp}", apps)
167167
r.Route("/@{user}/{workspace_and_agent}/apps/{workspaceapp}", apps)
168-
r.Get("/derp", derphttp.Handler(api.derpServer).ServeHTTP)
168+
r.Route("/derp", func(r chi.Router) {
169+
r.Get("/", derphttp.Handler(api.derpServer).ServeHTTP)
170+
// This is used when UDP is blocked, and latency must be checked via HTTP(s).
171+
r.Get("/latency-check", func(w http.ResponseWriter, r *http.Request) {
172+
w.WriteHeader(http.StatusOK)
173+
})
174+
})
169175

170176
r.Route("/api/v2", func(r chi.Router) {
171177
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {

coderd/coderd_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd_test
22

33
import (
44
"context"
5+
"net/http"
56
"net/netip"
67
"strconv"
78
"testing"
@@ -114,3 +115,12 @@ func TestDERP(t *testing.T) {
114115
w1.Close()
115116
w2.Close()
116117
}
118+
119+
func TestDERPLatencyCheck(t *testing.T) {
120+
t.Parallel()
121+
client := coderdtest.New(t, nil)
122+
res, err := client.Request(context.Background(), http.MethodGet, "/derp/latency-check", nil)
123+
require.NoError(t, err)
124+
defer res.Body.Close()
125+
require.Equal(t, http.StatusOK, res.StatusCode)
126+
}

coderd/coderdtest/authtest.go

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
168168
skipRoutes := map[string]string{
169169
"POST:/api/v2/users/logout": "Logging out deletes the API Key for other routes",
170170
"GET:/derp": "This requires a WebSocket upgrade!",
171+
"GET:/derp/latency-check": "This always returns a 200!",
171172
}
172173

173174
assertRoute := map[string]RouteCheck{

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
4949

5050
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
5151
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
52-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220831012541-a77bda274fd6
52+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20220901032724-2ed2977662a4
5353

5454
require (
5555
cdr.dev/slog v1.4.2-0.20220525200111-18dce5c2cd5f

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOu
352352
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
353353
github.com/coder/retry v1.3.0 h1:5lAAwt/2Cm6lVmnfBY7sOMXcBOwcwJhmV5QGSELIVWY=
354354
github.com/coder/retry v1.3.0/go.mod h1:tXuRgZgWjUnU5LZPT4lJh4ew2elUhexhlnXzrJWdyFY=
355-
github.com/coder/tailscale v1.1.1-0.20220831012541-a77bda274fd6 h1://ApBDDh58hFwMe0AzlgqJrGhzu6Rjk8fQXrR+mbhYE=
356-
github.com/coder/tailscale v1.1.1-0.20220831012541-a77bda274fd6/go.mod h1:MO+tWkQp2YIF3KBnnej/mQvgYccRS5Xk/IrEpZ4Z3BU=
355+
github.com/coder/tailscale v1.1.1-0.20220901032724-2ed2977662a4 h1:TXtMXPt4ds1pM9QrLsfiDEJv7KE8q0yRQGCkSepeKZ8=
356+
github.com/coder/tailscale v1.1.1-0.20220901032724-2ed2977662a4/go.mod h1:MO+tWkQp2YIF3KBnnej/mQvgYccRS5Xk/IrEpZ4Z3BU=
357357
github.com/coder/wireguard-go/tun/netstack v0.0.0-20220823170024-a78136eb0cab h1:9yEvRWXXfyKzXu8AqywCi+tFZAoqCy4wVcsXwuvZNMc=
358358
github.com/coder/wireguard-go/tun/netstack v0.0.0-20220823170024-a78136eb0cab/go.mod h1:TCJ66NtXh3urJotTdoYQOHHkyE899vOQl5TuF+WLSes=
359359
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=

0 commit comments

Comments
 (0)