@@ -405,14 +405,7 @@ fn handle_client_outer(stream: UnixStream) {
405405 if index. is_some ( ) {
406406 let index_guard = OpenedIndexCleanupGuard { index : index. unwrap ( ) } ;
407407 // 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) ;
416409 }
417410 {
418411 // clean up message slot
@@ -496,8 +489,27 @@ fn handle_client(mut index: OpenedIndexCleanupGuard,
496489 drop ( index) ; // make sure index instance is closed first
497490 return ; // now we end the loop. The client will notice the socket close.
498491 }
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 happened: unknown cause." . to_string ( )
508+ } ,
509+ } ;
510+ Message :: ResponseError ( msg)
511+ } ,
512+ } ;
501513
502514 // put the response in the queue
503515 {
0 commit comments