@@ -205,7 +205,7 @@ async fn power_up_and_wait_for_connection(
205
205
}
206
206
207
207
// handling connection to headset profile in own task
208
- let task_hsp = {
208
+ let mut task_hsp = {
209
209
if let Some ( mut handle_hsp) = handle_hsp {
210
210
Some ( tokio:: spawn ( async move {
211
211
let req = handle_hsp
@@ -226,15 +226,37 @@ async fn power_up_and_wait_for_connection(
226
226
}
227
227
} ;
228
228
229
+ /// we might have a tasks which should be aborted on errors
230
+ /// this function is taking care of this before next bluetooth
231
+ /// connection attempts
232
+ fn abort_tasks (
233
+ t1 : & mut Option < JoinHandle < Result < ( ) > > > ,
234
+ t2 : & mut Option < JoinHandle < Result < ProfileHandle > > > ,
235
+ ) {
236
+ if let Some ( task) = t1 {
237
+ task. abort ( ) ;
238
+ }
239
+ if let Some ( task) = t2 {
240
+ task. abort ( ) ;
241
+ }
242
+ }
243
+
229
244
let req = timeout ( bt_timeout, handle_aa. next ( ) )
230
- . await ?
245
+ . await
246
+ . map_err ( |e| {
247
+ abort_tasks ( & mut connect_task, & mut task_hsp) ;
248
+ e
249
+ } ) ?
231
250
. expect ( "received no connect request" ) ;
232
251
info ! (
233
252
"{} 📱 AA Wireless Profile: connect from: <b>{}</>" ,
234
253
NAME ,
235
254
req. device( )
236
255
) ;
237
- let stream = req. accept ( ) ?;
256
+ let stream = req. accept ( ) . map_err ( |e| {
257
+ abort_tasks ( & mut connect_task, & mut task_hsp) ;
258
+ e
259
+ } ) ?;
238
260
239
261
// we have a connection from phone, stop connect_task
240
262
if let Some ( task) = connect_task {
0 commit comments