@@ -405,14 +405,7 @@ fn handle_client_outer(stream: UnixStream) {
405
405
if index. is_some ( ) {
406
406
let index_guard = OpenedIndexCleanupGuard { index : index. unwrap ( ) } ;
407
407
// now start servicing instance requests
408
- let result = panic:: catch_unwind ( || {
409
- handle_client ( index_guard,
410
- reader,
411
- connection_id) ;
412
- } ) ;
413
- if result. is_err ( ) {
414
- println ! ( "panic happend!" )
415
- }
408
+ handle_client ( index_guard, reader, connection_id) ;
416
409
}
417
410
{
418
411
// clean up message slot
@@ -496,8 +489,27 @@ fn handle_client(mut index: OpenedIndexCleanupGuard,
496
489
drop ( index) ; // make sure index instance is closed first
497
490
return ; // now we end the loop. The client will notice the socket close.
498
491
}
499
- // process the message
500
- let response = process_message ( & mut index, msg) ;
492
+ // NOTE vmx 2017-12-05: I'm not really sure if passing on the `&mut index`
493
+ // is really safe. But it seems to work.
494
+ let result = panic:: catch_unwind ( panic:: AssertUnwindSafe ( || {
495
+ // process the message
496
+ process_message ( & mut index, msg)
497
+ } ) ) ;
498
+
499
+ let response = match result {
500
+ Ok ( resp) => resp,
501
+ Err ( panic) => {
502
+ let msg = match panic. downcast :: < String > ( ) {
503
+ Ok ( panic_msg) => {
504
+ format ! ( "panic happened: {}" , panic_msg)
505
+ } ,
506
+ Err ( _) => {
507
+ "panic happend: unknown cause." . to_string ( )
508
+ } ,
509
+ } ;
510
+ Message :: ResponseError ( msg)
511
+ } ,
512
+ } ;
501
513
502
514
// put the response in the queue
503
515
{
0 commit comments