MCPcopy Index your code
hub / github.com/coder/coder / agent

Struct agent

agent/agent.go:250–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250type agent struct {
251 clock quartz.Clock
252 logger slog.Logger
253 client Client
254 tailnetListenPort uint16
255 filesystem afero.Fs
256 logDir string
257 tempDir string
258 scriptDataDir string
259 listeningPortsHandler listeningPortsHandler
260 subsystems []codersdk.AgentSubsystem
261
262 reconnectingPTYTimeout time.Duration
263 reconnectingPTYServer *reconnectingpty.Server
264
265 // we track 2 contexts and associated cancel functions: "graceful" which is Done when it is time
266 // to start gracefully shutting down and "hard" which is Done when it is time to close
267 // everything down (regardless of whether graceful shutdown completed).
268 gracefulCtx context.Context
269 gracefulCancel context.CancelFunc
270 hardCtx context.Context
271 hardCancel context.CancelFunc
272
273 // closeMutex protects the following:
274 closeMutex sync.Mutex
275 closeWaitGroup sync.WaitGroup
276 coordDisconnected chan struct{}
277 closing bool
278 // note that once the network is set to non-nil, it is never modified, as with the statsReporter. So, routines
279 // that run after createOrUpdateNetwork and check the networkOK checkpoint do not need to hold the lock to use them.
280 network *tailnet.Conn
281 statsReporter *statsReporter
282 // end fields protected by closeMutex
283
284 environmentVariables map[string]string
285
286 manifest atomic.Pointer[agentsdk.Manifest] // manifest is atomic because values can change after reconnection.
287 // secrets are held separately from the manifest so that code paths that
288 // only need manifest data cannot accidentally access or leak secret
289 // values. Callers that need secrets must explicitly load this.
290 secrets atomic.Pointer[[]agentsdk.WorkspaceSecret]
291 reportMetadataInterval time.Duration
292 scriptRunner *agentscripts.Runner
293 announcementBanners atomic.Pointer[[]codersdk.BannerConfig] // announcementBanners is atomic because it is periodically updated.
294 announcementBannersRefreshInterval time.Duration
295 sshServer *agentssh.Server
296 sshMaxTimeout time.Duration
297 blockFileTransfer bool
298 blockReversePortForwarding bool
299 blockLocalPortForwarding bool
300
301 lifecycleUpdate chan struct{}
302 lifecycleReported chan codersdk.WorkspaceAgentLifecycle
303 lifecycleMu sync.RWMutex // Protects following.
304 lifecycleStates []agentsdk.PostLifecycleRequest
305 lifecycleLastReportedIndex int // Keeps track of the last lifecycle state we successfully reported.
306
307 reportConnectionsUpdate chan struct{}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected