fix(server): fix leakage of SessionMetaData (#728)

There are different reasons leading the server thread exits,
currently we only release the cached session data when client
exits normally. This fix covers all the cases.

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2021-09-19 02:36:15 +08:00 committed by GitHub
parent 72b0474d02
commit ac7bcf1169
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -170,19 +170,13 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
thread_handles.lock().unwrap().push( thread_handles.lock().unwrap().push(
thread::Builder::new() thread::Builder::new()
.name("server_router".to_string()) .name("server_router".to_string())
.spawn({ .spawn(move || {
let session_data = session_data.clone();
let os_input = os_input.clone();
let to_server = to_server.clone();
move || {
route_thread_main( route_thread_main(
session_data, session_data,
session_state, session_state,
os_input, os_input,
to_server, to_server,
) )
}
}) })
.unwrap(), .unwrap(),
); );
@ -267,7 +261,6 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
} }
} }
ServerInstruction::ClientExit => { ServerInstruction::ClientExit => {
*session_data.write().unwrap() = None;
os_input.send_to_client(ServerToClientMsg::Exit(ExitReason::Normal)); os_input.send_to_client(ServerToClientMsg::Exit(ExitReason::Normal));
break; break;
} }
@ -297,6 +290,10 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
} }
} }
} }
// Drop cached session data before exit.
*session_data.write().unwrap() = None;
thread_handles thread_handles
.lock() .lock()
.unwrap() .unwrap()