Skip to content

Commit f0fa578

Browse files
committed
other comments
1 parent 2943ac2 commit f0fa578

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func New(options *Options) *API {
327327
options.HealthcheckFunc = func(ctx context.Context, apiKey string) *healthcheck.Report {
328328
return healthcheck.Run(ctx, &healthcheck.ReportOptions{
329329
AccessURL: options.AccessURL,
330-
DERPMap: api.DERPMap().Clone(),
330+
DERPMap: api.DERPMap(),
331331
APIKey: apiKey,
332332
})
333333
}

enterprise/coderd/coderd.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,22 +476,38 @@ func (api *API) updateEntitlements(ctx context.Context) error {
476476
//
477477
// Two ints are returned, the first is the starting region ID for proxies, and
478478
// the second is the maximum region ID that already exists in the DERP map.
479-
func getProxyDERPStartingRegionID(derpMap *tailcfg.DERPMap) (sID int, mID int) {
480-
maxRegionID := 0
479+
func getProxyDERPStartingRegionID(derpMap *tailcfg.DERPMap) (sID int64, mID int64) {
480+
var maxRegionID int64
481481
for _, region := range derpMap.Regions {
482-
if region.RegionID > maxRegionID {
483-
maxRegionID = region.RegionID
482+
rid := int64(region.RegionID)
483+
if rid > maxRegionID {
484+
maxRegionID = rid
484485
}
485486
}
486487
if maxRegionID < 0 {
487488
maxRegionID = 0
488489
}
489490

490491
// Round to the nearest 10,000 with a sufficient buffer of at least 2,000.
492+
// The buffer allows for future "fixed" regions to be added to the base DERP
493+
// map without conflicting with proxy region IDs (standard DERP maps usually
494+
// use incrementing IDs for new regions).
495+
//
496+
// Example:
497+
// maxRegionID = -2_000 -> startingRegionID = 10_000
498+
// maxRegionID = 8_000 -> startingRegionID = 10_000
499+
// maxRegionID = 8_500 -> startingRegionID = 20_000
500+
// maxRegionID = 12_000 -> startingRegionID = 20_000
501+
// maxRegionID = 20_000 -> startingRegionID = 30_000
491502
const roundStartingRegionID = 10_000
492503
const startingRegionIDBuffer = 2_000
504+
// Add the buffer first.
493505
startingRegionID := maxRegionID + startingRegionIDBuffer
494-
startingRegionID = int(math.Ceil(float64(startingRegionID)/roundStartingRegionID) * roundStartingRegionID)
506+
// Round UP to the nearest 10,000. Go's math.Ceil rounds up to the nearest
507+
// integer, so we need to divide by 10,000 first and then multiply by
508+
// 10,000.
509+
startingRegionID = int64(math.Ceil(float64(startingRegionID)/roundStartingRegionID) * roundStartingRegionID)
510+
// This should never be hit but it's here just in case.
495511
if startingRegionID < roundStartingRegionID {
496512
startingRegionID = roundStartingRegionID
497513
}
@@ -565,7 +581,7 @@ func derpMapper(logger slog.Logger, proxyHealth *proxyhealth.ProxyHealth) func(*
565581
// This should be impossible to hit as the IDs are enforced to be
566582
// unique by the database and the computed ID is greater than any
567583
// existing ID in the DERP map.
568-
regionID := startingRegionID + int(status.Proxy.RegionID)
584+
regionID := int(startingRegionID) + int(status.Proxy.RegionID)
569585
regionCode := fmt.Sprintf("coder_%s", strings.ToLower(status.Proxy.Name))
570586
for _, r := range derpMap.Regions {
571587
if r.RegionID == regionID || r.RegionCode == regionCode {

enterprise/coderd/workspaceproxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/sha256"
66
"database/sql"
7+
"flag"
78
"fmt"
89
"net/http"
910
"net/url"
@@ -531,7 +532,10 @@ func (api *API) workspaceProxyRegister(rw http.ResponseWriter, r *http.Request)
531532
return
532533
}
533534

534-
if req.Version != buildinfo.Version() {
535+
// Version check should be forced in non-dev builds and when running in
536+
// tests.
537+
shouldForceVersion := !buildinfo.IsDev() || flag.Lookup("test.v") != nil
538+
if shouldForceVersion && req.Version != buildinfo.Version() {
535539
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
536540
Message: "Version mismatch.",
537541
Detail: fmt.Sprintf("Proxy version %q does not match primary server version %q", req.Version, buildinfo.Version()),

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ func (c *Client) RegisterWorkspaceProxyLoop(ctx context.Context, opts RegisterWo
350350
failureFn(xerrors.Errorf("exceeded re-registration failure count of %d: last error: %w", opts.MaxFailureCount, err))
351351
return
352352
}
353+
continue
353354
}
354355
failedAttempts = 0
355356

0 commit comments

Comments
 (0)