@@ -135,10 +135,18 @@ impl FlightExchange {
135
135
) -> FlightExchange {
136
136
let mut streaming = streaming. into_inner ( ) ;
137
137
let ( tx, rx) = async_channel:: bounded ( 1 ) ;
138
+
138
139
common_base:: base:: tokio:: spawn ( async move {
139
140
while let Some ( message) = streaming. next ( ) . await {
140
- if let Err ( _cause) = tx. send ( message) . await {
141
- break ;
141
+ match message {
142
+ Ok ( message) if DataPacket :: is_closing_client ( & message) => {
143
+ break ;
144
+ }
145
+ other => {
146
+ if let Err ( _c) = tx. send ( other) . await {
147
+ break ;
148
+ }
149
+ }
142
150
}
143
151
}
144
152
} ) ;
@@ -159,8 +167,15 @@ impl FlightExchange {
159
167
let ( tx, request_rx) = async_channel:: bounded ( 1 ) ;
160
168
common_base:: base:: tokio:: spawn ( async move {
161
169
while let Some ( message) = streaming. next ( ) . await {
162
- if let Err ( _cause) = tx. send ( message) . await {
163
- break ;
170
+ match message {
171
+ Ok ( flight_data) if DataPacket :: is_closing_client ( & flight_data) => {
172
+ break ;
173
+ }
174
+ other => {
175
+ if let Err ( _cause) = tx. send ( other) . await {
176
+ break ;
177
+ }
178
+ }
164
179
}
165
180
}
166
181
} ) ;
@@ -282,7 +297,9 @@ impl ClientFlightExchange {
282
297
if !self . is_closed_response . fetch_or ( true , Ordering :: SeqCst )
283
298
&& self . state . response_count . fetch_sub ( 1 , Ordering :: AcqRel ) == 1
284
299
{
285
- self . response_tx . close ( ) ;
300
+ let _ = self
301
+ . response_tx
302
+ . send_blocking ( FlightData :: from ( DataPacket :: ClosingClient ) ) ;
286
303
}
287
304
}
288
305
}
@@ -304,17 +321,8 @@ impl Clone for ClientFlightExchange {
304
321
305
322
impl Drop for ClientFlightExchange {
306
323
fn drop ( & mut self ) {
307
- if !self . is_closed_request . fetch_or ( true , Ordering :: SeqCst )
308
- && self . state . request_count . fetch_sub ( 1 , Ordering :: AcqRel ) == 1
309
- {
310
- self . request_rx . close ( ) ;
311
- }
312
-
313
- if !self . is_closed_response . fetch_or ( true , Ordering :: SeqCst )
314
- && self . state . response_count . fetch_sub ( 1 , Ordering :: AcqRel ) == 1
315
- {
316
- self . response_tx . close ( ) ;
317
- }
324
+ self . close_input ( ) ;
325
+ self . close_output ( ) ;
318
326
}
319
327
}
320
328
@@ -398,7 +406,9 @@ impl ServerFlightExchange {
398
406
if !self . is_closed_response . fetch_or ( true , Ordering :: SeqCst )
399
407
&& self . state . response_count . fetch_sub ( 1 , Ordering :: AcqRel ) == 1
400
408
{
401
- self . response_tx . close ( ) ;
409
+ let _ = self
410
+ . response_tx
411
+ . send_blocking ( Ok ( FlightData :: from ( DataPacket :: ClosingClient ) ) ) ;
402
412
}
403
413
}
404
414
}
0 commit comments