@@ -57,23 +57,29 @@ func New(options ...Option) http.Handler {
57
57
}
58
58
59
59
func (ch * devcontainersHandler ) ServeHTTP (rw http.ResponseWriter , r * http.Request ) {
60
- ct , err := ch .getContainers (r .Context ())
61
- if err != nil {
62
- if errors .Is (err , context .Canceled ) {
63
- httpapi .Write (r .Context (), rw , http .StatusRequestTimeout , codersdk.Response {
60
+ select {
61
+ case <- r .Context ().Done ():
62
+ // Client went away.
63
+ return
64
+ default :
65
+ ct , err := ch .getContainers (r .Context ())
66
+ if err != nil {
67
+ if errors .Is (err , context .Canceled ) {
68
+ httpapi .Write (r .Context (), rw , http .StatusRequestTimeout , codersdk.Response {
69
+ Message : "Could not get containers." ,
70
+ Detail : "Took too long to list containers." ,
71
+ })
72
+ return
73
+ }
74
+ httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
64
75
Message : "Could not get containers." ,
65
- Detail : "Took too long to list containers." ,
76
+ Detail : err . Error () ,
66
77
})
67
78
return
68
79
}
69
- httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
70
- Message : "Could not get containers." ,
71
- Detail : err .Error (),
72
- })
73
- return
74
- }
75
80
76
- httpapi .Write (r .Context (), rw , http .StatusOK , ct )
81
+ httpapi .Write (r .Context (), rw , http .StatusOK , ct )
82
+ }
77
83
}
78
84
79
85
func (ch * devcontainersHandler ) getContainers (ctx context.Context ) (codersdk.WorkspaceAgentListContainersResponse , error ) {
0 commit comments