File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -194,9 +194,20 @@ func (s *Server) Run() error {
194
194
g , ctx := errgroup .WithContext (ctx )
195
195
g .Go (func () error { return s .dispatchLoop (ctx ) })
196
196
g .Go (func () error { return s .writeLoop (ctx ) })
197
- g .Go (func () error { return s .readLoop (ctx ) })
198
197
199
- if err := g .Wait (); err != nil && ! errors .Is (err , io .EOF ) {
198
+ // Don't run readLoop in the group, as it blocks on stdin read and cannot be cancelled.
199
+ readLoopErr := make (chan error , 1 )
200
+ g .Go (func () error {
201
+ select {
202
+ case <- ctx .Done ():
203
+ return ctx .Err ()
204
+ case err := <- readLoopErr :
205
+ return err
206
+ }
207
+ })
208
+ go func () { readLoopErr <- s .readLoop (ctx ) }()
209
+
210
+ if err := g .Wait (); err != nil && ! errors .Is (err , io .EOF ) && ctx .Err () != nil {
200
211
return err
201
212
}
202
213
return nil
You can’t perform that action at this time.
0 commit comments