mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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>
This commit is contained in:
+12
-6
@@ -936,7 +936,7 @@ func (a *agent) run() (retErr error) {
|
||||
connMan.startAgentAPI("send logs", gracefulShutdownBehaviorRemain,
|
||||
func(ctx context.Context, aAPI proto.DRPCAgentClient24) error {
|
||||
err := a.logSender.SendLoop(ctx, aAPI)
|
||||
if xerrors.Is(err, agentsdk.LogLimitExceededError) {
|
||||
if xerrors.Is(err, agentsdk.ErrLogLimitExceeded) {
|
||||
// we don't want this error to tear down the API connection and propagate to the
|
||||
// other routines that use the API. The LogSender has already dropped a warning
|
||||
// log, so just return nil here.
|
||||
@@ -1564,9 +1564,13 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
|
||||
}
|
||||
for conn, counts := range networkStats {
|
||||
stats.ConnectionsByProto[conn.Proto.String()]++
|
||||
// #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
|
||||
stats.RxBytes += int64(counts.RxBytes)
|
||||
// #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
|
||||
stats.RxPackets += int64(counts.RxPackets)
|
||||
// #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
|
||||
stats.TxBytes += int64(counts.TxBytes)
|
||||
// #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
|
||||
stats.TxPackets += int64(counts.TxPackets)
|
||||
}
|
||||
|
||||
@@ -1619,11 +1623,12 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
|
||||
wg.Wait()
|
||||
sort.Float64s(durations)
|
||||
durationsLength := len(durations)
|
||||
if durationsLength == 0 {
|
||||
switch {
|
||||
case durationsLength == 0:
|
||||
stats.ConnectionMedianLatencyMs = -1
|
||||
} else if durationsLength%2 == 0 {
|
||||
case durationsLength%2 == 0:
|
||||
stats.ConnectionMedianLatencyMs = (durations[durationsLength/2-1] + durations[durationsLength/2]) / 2
|
||||
} else {
|
||||
default:
|
||||
stats.ConnectionMedianLatencyMs = durations[durationsLength/2]
|
||||
}
|
||||
// Convert from microseconds to milliseconds.
|
||||
@@ -1730,7 +1735,7 @@ func (a *agent) HTTPDebug() http.Handler {
|
||||
r.Get("/debug/magicsock", a.HandleHTTPDebugMagicsock)
|
||||
r.Get("/debug/magicsock/debug-logging/{state}", a.HandleHTTPMagicsockDebugLoggingState)
|
||||
r.Get("/debug/manifest", a.HandleHTTPDebugManifest)
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.NotFound(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_, _ = w.Write([]byte("404 not found"))
|
||||
})
|
||||
@@ -2016,7 +2021,7 @@ func (a *apiConnRoutineManager) wait() error {
|
||||
}
|
||||
|
||||
func PrometheusMetricsHandler(prometheusRegistry *prometheus.Registry, logger slog.Logger) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
|
||||
// Based on: https://github.com/tailscale/tailscale/blob/280255acae604796a1113861f5a84e6fa2dc6121/ipn/localapi/localapi.go#L489
|
||||
@@ -2052,5 +2057,6 @@ func WorkspaceKeySeed(workspaceID uuid.UUID, agentName string) (int64, error) {
|
||||
return 42, err
|
||||
}
|
||||
|
||||
// #nosec G115 - Safe conversion to generate int64 hash from Sum64, data loss acceptable
|
||||
return int64(h.Sum64()), nil
|
||||
}
|
||||
|
||||
@@ -453,8 +453,9 @@ func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentContainer, []str
|
||||
hostPortContainers[hp] = append(hostPortContainers[hp], in.ID)
|
||||
}
|
||||
out.Ports = append(out.Ports, codersdk.WorkspaceAgentContainerPort{
|
||||
Network: network,
|
||||
Port: cp,
|
||||
Network: network,
|
||||
Port: cp,
|
||||
// #nosec G115 - Safe conversion since Docker ports are limited to uint16 range
|
||||
HostPort: uint16(hp),
|
||||
HostIP: p.HostIP,
|
||||
})
|
||||
@@ -497,12 +498,14 @@ func convertDockerPort(in string) (uint16, string, error) {
|
||||
if err != nil {
|
||||
return 0, "", xerrors.Errorf("invalid port format: %s", in)
|
||||
}
|
||||
// #nosec G115 - Safe conversion since Docker TCP ports are limited to uint16 range
|
||||
return uint16(p), "tcp", nil
|
||||
case 2:
|
||||
p, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return 0, "", xerrors.Errorf("invalid port format: %s", in)
|
||||
}
|
||||
// #nosec G115 - Safe conversion since Docker ports are limited to uint16 range
|
||||
return uint16(p), parts[1], nil
|
||||
default:
|
||||
return 0, "", xerrors.Errorf("invalid port format: %s", in)
|
||||
|
||||
@@ -28,6 +28,7 @@ func BenchmarkGenerateDeterministicKey(b *testing.B) {
|
||||
for range b.N {
|
||||
// always record the result of DeterministicPrivateKey to prevent
|
||||
// the compiler eliminating the function call.
|
||||
// #nosec G404 - Using math/rand is acceptable for benchmarking deterministic keys
|
||||
r = agentrsa.GenerateDeterministicKey(rand.Int64())
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
|
||||
slog.F("destination_port", destinationPort))
|
||||
return true
|
||||
},
|
||||
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool {
|
||||
PtyCallback: func(_ ssh.Context, _ ssh.Pty) bool {
|
||||
return true
|
||||
},
|
||||
ReversePortForwardingCallback: func(ctx ssh.Context, bindHost string, bindPort uint32) bool {
|
||||
@@ -240,7 +240,7 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
|
||||
"cancel-streamlocal-forward@openssh.com": unixForwardHandler.HandleSSHRequest,
|
||||
},
|
||||
X11Callback: s.x11Callback,
|
||||
ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig {
|
||||
ServerConfigCallback: func(_ ssh.Context) *gossh.ServerConfig {
|
||||
return &gossh.ServerConfig{
|
||||
NoClientAuth: true,
|
||||
}
|
||||
@@ -702,6 +702,7 @@ func (s *Server) startPTYSession(logger slog.Logger, session ptySession, magicTy
|
||||
windowSize = nil
|
||||
continue
|
||||
}
|
||||
// #nosec G115 - Safe conversions for terminal dimensions which are expected to be within uint16 range
|
||||
resizeErr := ptty.Resize(uint16(win.Height), uint16(win.Width))
|
||||
// If the pty is closed, then command has exited, no need to log.
|
||||
if resizeErr != nil && !errors.Is(resizeErr, pty.ErrClosed) {
|
||||
|
||||
@@ -116,7 +116,8 @@ func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) (displayNumber int, ha
|
||||
OriginatorPort uint32
|
||||
}{
|
||||
OriginatorAddress: tcpAddr.IP.String(),
|
||||
OriginatorPort: uint32(tcpAddr.Port),
|
||||
// #nosec G115 - Safe conversion as TCP port numbers are within uint32 range (0-65535)
|
||||
OriginatorPort: uint32(tcpAddr.Port),
|
||||
}))
|
||||
if err != nil {
|
||||
s.logger.Warn(ctx, "failed to open X11 channel", slog.Error(err))
|
||||
@@ -294,6 +295,7 @@ func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string
|
||||
return xerrors.Errorf("failed to write family: %w", err)
|
||||
}
|
||||
|
||||
// #nosec G115 - Safe conversion for host name length which is expected to be within uint16 range
|
||||
err = binary.Write(file, binary.BigEndian, uint16(len(host)))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to write host length: %w", err)
|
||||
@@ -303,6 +305,7 @@ func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string
|
||||
return xerrors.Errorf("failed to write host: %w", err)
|
||||
}
|
||||
|
||||
// #nosec G115 - Safe conversion for display name length which is expected to be within uint16 range
|
||||
err = binary.Write(file, binary.BigEndian, uint16(len(display)))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to write display length: %w", err)
|
||||
@@ -312,6 +315,7 @@ func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string
|
||||
return xerrors.Errorf("failed to write display: %w", err)
|
||||
}
|
||||
|
||||
// #nosec G115 - Safe conversion for auth protocol length which is expected to be within uint16 range
|
||||
err = binary.Write(file, binary.BigEndian, uint16(len(authProtocol)))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to write auth protocol length: %w", err)
|
||||
@@ -321,6 +325,7 @@ func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string
|
||||
return xerrors.Errorf("failed to write auth protocol: %w", err)
|
||||
}
|
||||
|
||||
// #nosec G115 - Safe conversion for auth cookie length which is expected to be within uint16 range
|
||||
err = binary.Write(file, binary.BigEndian, uint16(len(authCookieBytes)))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to write auth cookie length: %w", err)
|
||||
|
||||
+2
-2
@@ -167,8 +167,8 @@ func shouldStartTicker(app codersdk.WorkspaceApp) bool {
|
||||
return app.Healthcheck.URL != "" && app.Healthcheck.Interval > 0 && app.Healthcheck.Threshold > 0
|
||||
}
|
||||
|
||||
func healthChanged(old map[uuid.UUID]codersdk.WorkspaceAppHealth, new map[uuid.UUID]codersdk.WorkspaceAppHealth) bool {
|
||||
for name, newValue := range new {
|
||||
func healthChanged(old map[uuid.UUID]codersdk.WorkspaceAppHealth, updated map[uuid.UUID]codersdk.WorkspaceAppHealth) bool {
|
||||
for name, newValue := range updated {
|
||||
oldValue, found := old[name]
|
||||
if !found {
|
||||
return true
|
||||
|
||||
+4
-3
@@ -89,21 +89,22 @@ func (a *agent) collectMetrics(ctx context.Context) []*proto.Stats_Metric {
|
||||
for _, metric := range metricFamily.GetMetric() {
|
||||
labels := toAgentMetricLabels(metric.Label)
|
||||
|
||||
if metric.Counter != nil {
|
||||
switch {
|
||||
case metric.Counter != nil:
|
||||
collected = append(collected, &proto.Stats_Metric{
|
||||
Name: metricFamily.GetName(),
|
||||
Type: proto.Stats_Metric_COUNTER,
|
||||
Value: metric.Counter.GetValue(),
|
||||
Labels: labels,
|
||||
})
|
||||
} else if metric.Gauge != nil {
|
||||
case metric.Gauge != nil:
|
||||
collected = append(collected, &proto.Stats_Metric{
|
||||
Name: metricFamily.GetName(),
|
||||
Type: proto.Stats_Metric_GAUGE,
|
||||
Value: metric.Gauge.GetValue(),
|
||||
Labels: labels,
|
||||
})
|
||||
} else {
|
||||
default:
|
||||
a.logger.Error(ctx, "unsupported metric type", slog.F("type", metricFamily.Type.String()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ func newBuffered(ctx context.Context, logger slog.Logger, execer agentexec.Exece
|
||||
// Add TERM then start the command with a pty. pty.Cmd duplicates Path as the
|
||||
// first argument so remove it.
|
||||
cmdWithEnv := execer.PTYCommandContext(ctx, cmd.Path, cmd.Args[1:]...)
|
||||
//nolint:gocritic
|
||||
cmdWithEnv.Env = append(rpty.command.Env, "TERM=xterm-256color")
|
||||
cmdWithEnv.Dir = rpty.command.Dir
|
||||
ptty, process, err := pty.Start(cmdWithEnv)
|
||||
@@ -236,7 +237,7 @@ func (rpty *bufferedReconnectingPTY) Wait() {
|
||||
_, _ = rpty.state.waitForState(StateClosing)
|
||||
}
|
||||
|
||||
func (rpty *bufferedReconnectingPTY) Close(error error) {
|
||||
func (rpty *bufferedReconnectingPTY) Close(err error) {
|
||||
// The closing state change will be handled by the lifecycle.
|
||||
rpty.state.setState(StateClosing, error)
|
||||
rpty.state.setState(StateClosing, err)
|
||||
}
|
||||
|
||||
@@ -225,6 +225,7 @@ func (rpty *screenReconnectingPTY) doAttach(ctx context.Context, conn net.Conn,
|
||||
rpty.command.Path,
|
||||
// pty.Cmd duplicates Path as the first argument so remove it.
|
||||
}, rpty.command.Args[1:]...)...)
|
||||
//nolint:gocritic
|
||||
cmd.Env = append(rpty.command.Env, "TERM=xterm-256color")
|
||||
cmd.Dir = rpty.command.Dir
|
||||
ptty, process, err := pty.Start(cmd, pty.WithPTYOption(
|
||||
@@ -340,6 +341,7 @@ func (rpty *screenReconnectingPTY) sendCommand(ctx context.Context, command stri
|
||||
// -X runs a command in the matching session.
|
||||
"-X", command,
|
||||
)
|
||||
//nolint:gocritic
|
||||
cmd.Env = append(rpty.command.Env, "TERM=xterm-256color")
|
||||
cmd.Dir = rpty.command.Dir
|
||||
cmd.Stdout = &stdout
|
||||
|
||||
Reference in New Issue
Block a user