@@ -83,6 +83,7 @@ func (s *stdioTransport) run(
83
83
84
84
reader := bufio .NewReader (s .in )
85
85
go func () {
86
+ defer close (s .stoppedReadingResponses )
86
87
out:
87
88
for {
88
89
select {
@@ -106,38 +107,28 @@ func (s *stdioTransport) run(
106
107
}
107
108
}
108
109
}
109
- close (s .stoppedReadingResponses )
110
110
}()
111
111
112
112
go func () {
113
+ defer close (s .stoppedReadingInput )
113
114
out:
114
115
for {
115
- select {
116
- case <- s .shuttingDown :
117
- break out
118
- default :
119
- input , err := reader .ReadBytes ('\n' )
120
- if err != nil {
121
- if ! errors .Is (err , io .EOF ) {
122
- srv .GetLogger ().LogEvent (foxyevent.StdioFailedReadingInput {Err : err })
123
- }
124
- break out
116
+ input , err := reader .ReadBytes ('\n' )
117
+ if err != nil {
118
+ if ! errors .Is (err , io .EOF ) {
119
+ srv .GetLogger ().LogEvent (foxyevent.StdioFailedReadingInput {Err : err })
125
120
}
126
- srv . Handle ( ctx , input )
121
+ break out
127
122
}
123
+ srv .Handle (ctx , input )
128
124
}
129
- close (s .stoppedReadingInput )
130
125
}()
131
126
132
127
// wait for either shutting down or stopped reading input
133
128
select {
134
129
case <- s .shuttingDown :
135
- // if we got shutting down signal,
136
- // we need to wait until we stop reading input,
137
- // which waits for shutdown by itself
138
- <- s .stoppedReadingInput
139
130
case <- s .stoppedReadingInput :
140
- // if we stopped reading input, we can now initiate shutdown
131
+ // if we stopped reading input, we can now initiate transport shutdown
141
132
close (s .shuttingDown )
142
133
}
143
134
0 commit comments