@@ -195,7 +195,7 @@ impl WriteProxyConnection {
195
195
196
196
let ( builder, new_status, new_frame_no) = match res {
197
197
Ok ( res) => res,
198
- Err ( e @ Error :: StreamDisconnect ) => {
198
+ Err ( e @ ( Error :: PrimaryStreamDisconnect | Error :: PrimaryStreamMisuse ) ) => {
199
199
// drop the connection
200
200
self . remote_conn . lock ( ) . await . take ( ) ;
201
201
return Err ( e) ;
@@ -290,23 +290,28 @@ impl RemoteConnection {
290
290
self . request_sender
291
291
. send ( req)
292
292
. await
293
- . map_err ( |_| Error :: StreamDisconnect ) ?;
293
+ . map_err ( |_| Error :: PrimaryStreamDisconnect ) ?;
294
294
295
- ' outer : while let Some ( resp) = self . response_stream . next ( ) . await {
295
+ while let Some ( resp) = self . response_stream . next ( ) . await {
296
296
match resp {
297
297
Ok ( resp) => {
298
- // todo: handle interuption
299
- if resp. request_id != request_id {
300
- todo ! ( "stream misuse: connection should be serialized" ) ;
298
+ // there was an interuption, and we moved to the next query
299
+ if resp. request_id > request_id {
300
+ return Err ( Error :: PrimaryStreamInterupted )
301
301
}
302
302
303
- if !response_cb ( resp. response . unwrap ( ) ) ? {
304
- break ' outer;
303
+ // we can ignore response for previously interupted requests
304
+ if resp. request_id < request_id {
305
+ continue ;
306
+ }
307
+
308
+ if !response_cb ( resp. response . ok_or ( Error :: PrimaryStreamMisuse ) ?) ? {
309
+ break ;
305
310
}
306
311
}
307
312
Err ( e) => {
308
- tracing:: error!( "received error from connection stream: {e}" ) ;
309
- return Err ( Error :: StreamDisconnect ) ;
313
+ tracing:: error!( "received an error from connection stream: {e}" ) ;
314
+ return Err ( Error :: PrimaryStreamDisconnect ) ;
310
315
}
311
316
}
312
317
}
@@ -326,16 +331,16 @@ impl RemoteConnection {
326
331
match response {
327
332
exec_resp:: Response :: ProgramResp ( resp) => {
328
333
for step in resp. steps {
329
- let Some ( step) = step. step else { panic ! ( "invalid pgm" ) } ;
334
+ let Some ( step) = step. step else { return Err ( Error :: PrimaryStreamMisuse ) } ;
330
335
match step {
331
336
Step :: Init ( _) => builder. init ( & builder_config) ?,
332
337
Step :: BeginStep ( _) => builder. begin_step ( ) ?,
333
338
Step :: FinishStep ( FinishStep {
334
339
affected_row_count,
335
340
last_insert_rowid,
336
341
} ) => builder. finish_step ( affected_row_count, last_insert_rowid) ?,
337
- Step :: StepError ( StepError { error } ) => builder
338
- . step_error ( crate :: error:: Error :: RpcQueryError ( error . unwrap ( ) ) ) ?,
342
+ Step :: StepError ( StepError { error : Some ( err ) } ) => builder
343
+ . step_error ( crate :: error:: Error :: RpcQueryError ( err ) ) ?,
339
344
Step :: ColsDescription ( ColsDescription { columns } ) => {
340
345
let cols = columns. iter ( ) . map ( |c| Column {
341
346
name : & c. name ,
@@ -365,12 +370,12 @@ impl RemoteConnection {
365
370
builder. finish ( last_frame_no, txn_status) ?;
366
371
return Ok ( false ) ;
367
372
}
368
- _ => todo ! ( "invalid request" ) ,
373
+ _ => return Err ( Error :: PrimaryStreamMisuse ) ,
369
374
}
370
375
}
371
376
}
372
- exec_resp:: Response :: DescribeResp ( _) => todo ! ( "invalid resp" ) ,
373
- exec_resp:: Response :: Error ( _ ) => todo ! ( ) ,
377
+ exec_resp:: Response :: DescribeResp ( _) => return Err ( Error :: PrimaryStreamMisuse ) ,
378
+ exec_resp:: Response :: Error ( e ) => return Err ( Error :: RpcQueryError ( e ) ) ,
374
379
}
375
380
376
381
Ok ( true )
@@ -410,12 +415,12 @@ impl RemoteConnection {
410
415
is_explain : resp. is_explain ,
411
416
is_readonly : resp. is_readonly ,
412
417
} ) ;
418
+
419
+ Ok ( false )
413
420
}
414
- exec_resp:: Response :: Error ( _ ) => todo ! ( ) ,
415
- exec_resp:: Response :: ProgramResp ( _) => todo ! ( ) ,
421
+ exec_resp:: Response :: Error ( e ) => Err ( Error :: RpcQueryError ( e ) ) ,
422
+ exec_resp:: Response :: ProgramResp ( _) => Err ( Error :: PrimaryStreamMisuse ) ,
416
423
}
417
-
418
- Ok ( false )
419
424
} ;
420
425
421
426
self . make_request (
@@ -424,7 +429,7 @@ impl RemoteConnection {
424
429
)
425
430
. await ?;
426
431
427
- Ok ( out. unwrap ( ) )
432
+ out. ok_or ( Error :: PrimaryStreamMisuse )
428
433
}
429
434
}
430
435
0 commit comments