@@ -50,7 +50,7 @@ func (api *API) workspaceAgent(rw http.ResponseWriter, r *http.Request) {
50
50
})
51
51
return
52
52
}
53
- apiAgent , err := convertWorkspaceAgent (workspaceAgent , convertApps (dbApps ), api .AgentConnectionUpdateFrequency )
53
+ apiAgent , err := convertWorkspaceAgent (workspaceAgent , convertApps (dbApps ), api .AgentInactiveDisconnectTimeout )
54
54
if err != nil {
55
55
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
56
56
Message : "Internal error reading workspace agent." ,
@@ -74,7 +74,7 @@ func (api *API) workspaceAgentDial(rw http.ResponseWriter, r *http.Request) {
74
74
httpapi .ResourceNotFound (rw )
75
75
return
76
76
}
77
- apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentConnectionUpdateFrequency )
77
+ apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentInactiveDisconnectTimeout )
78
78
if err != nil {
79
79
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
80
80
Message : "Internal error reading workspace agent." ,
@@ -121,7 +121,7 @@ func (api *API) workspaceAgentDial(rw http.ResponseWriter, r *http.Request) {
121
121
122
122
func (api * API ) workspaceAgentMetadata (rw http.ResponseWriter , r * http.Request ) {
123
123
workspaceAgent := httpmw .WorkspaceAgent (r )
124
- apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentConnectionUpdateFrequency )
124
+ apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentInactiveDisconnectTimeout )
125
125
if err != nil {
126
126
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
127
127
Message : "Internal error reading workspace agent." ,
@@ -401,7 +401,7 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
401
401
httpapi .ResourceNotFound (rw )
402
402
return
403
403
}
404
- apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentConnectionUpdateFrequency )
404
+ apiAgent , err := convertWorkspaceAgent (workspaceAgent , nil , api .AgentInactiveDisconnectTimeout )
405
405
if err != nil {
406
406
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
407
407
Message : "Internal error reading workspace agent." ,
@@ -689,7 +689,7 @@ func inetToNetaddr(inet pqtype.Inet) netaddr.IPPrefix {
689
689
return ipp
690
690
}
691
691
692
- func convertWorkspaceAgent (dbAgent database.WorkspaceAgent , apps []codersdk.WorkspaceApp , agentUpdateFrequency time.Duration ) (codersdk.WorkspaceAgent , error ) {
692
+ func convertWorkspaceAgent (dbAgent database.WorkspaceAgent , apps []codersdk.WorkspaceApp , agentInactiveDisconnectTimeout time.Duration ) (codersdk.WorkspaceAgent , error ) {
693
693
var envs map [string ]string
694
694
if dbAgent .EnvironmentVariables .Valid {
695
695
err := json .Unmarshal (dbAgent .EnvironmentVariables .RawMessage , & envs )
@@ -734,13 +734,13 @@ func convertWorkspaceAgent(dbAgent database.WorkspaceAgent, apps []codersdk.Work
734
734
// If we've disconnected after our last connection, we know the
735
735
// agent is no longer connected.
736
736
workspaceAgent .Status = codersdk .WorkspaceAgentDisconnected
737
- case agentUpdateFrequency * 2 >= database .Now ().Sub (dbAgent .LastConnectedAt .Time ):
738
- // The connection updated it's timestamp within the update frequency.
739
- // We multiply by two to allow for some lag.
740
- workspaceAgent .Status = codersdk .WorkspaceAgentConnected
741
- case database .Now ().Sub (dbAgent .LastConnectedAt .Time ) > agentUpdateFrequency * 2 :
737
+ case database .Now ().Sub (dbAgent .LastConnectedAt .Time ) > agentInactiveDisconnectTimeout :
742
738
// The connection died without updating the last connected.
743
739
workspaceAgent .Status = codersdk .WorkspaceAgentDisconnected
740
+ case dbAgent .LastConnectedAt .Valid :
741
+ // The agent should be assumed connected if it's under inactivity timeouts
742
+ // and last connected at has been properly set.
743
+ workspaceAgent .Status = codersdk .WorkspaceAgentConnected
744
744
}
745
745
746
746
return workspaceAgent , nil
0 commit comments