@@ -44,18 +44,30 @@ struct PreviewRdParams {
4444pub fn start ( target_port : u16 ) -> anyhow:: Result < u16 > {
4545 let source_port = HelpProxy :: get_os_assigned_port ( ) ?;
4646
47- spawn ! ( "ark-help-proxy" , move || {
48- match task( source_port, target_port) {
49- Ok ( value) => log:: info!( "Help proxy server exited with value: {:?}" , value) ,
50- Err ( error) => log:: error!( "Help proxy server exited unexpectedly: {}" , error) ,
51- }
47+ spawn ! ( "ark-help-proxy" , move || -> anyhow:: Result <( ) > {
48+ // Create a single-threaded Tokio runtime to spare stack memory. The
49+ // help proxy server does not need to be high performance.
50+ // Note that `new_current_thread()` seems to consume much more memory.
51+ let rt = tokio:: runtime:: Builder :: new_multi_thread( )
52+ . enable_all( )
53+ . worker_threads( 1 )
54+ . build( ) ?;
55+
56+ // Execute the task within the runtime.
57+ rt. block_on( async {
58+ match task( source_port, target_port) . await {
59+ Ok ( value) => log:: info!( "Help proxy server exited with value: {:?}" , value) ,
60+ Err ( error) => log:: error!( "Help proxy server exited unexpectedly: {}" , error) ,
61+ }
62+ } ) ;
63+
64+ Ok ( ( ) )
5265 } ) ;
5366
5467 Ok ( source_port)
5568}
5669
5770// The help proxy main entry point.
58- #[ tokio:: main]
5971async fn task ( source_port : u16 , target_port : u16 ) -> anyhow:: Result < ( ) > {
6072 // Create the help proxy.
6173 let help_proxy = HelpProxy :: new ( source_port, target_port) ?;
@@ -101,7 +113,8 @@ impl HelpProxy {
101113 . service ( preview_img)
102114 . default_service ( web:: to ( proxy_request) )
103115 } )
104- . bind ( ( "127.0.0.1" , self . source_port ) ) ?;
116+ . bind ( ( "127.0.0.1" , self . source_port ) ) ?
117+ . workers ( 1 ) ;
105118
106119 // Run the server.
107120 Ok ( server. run ( ) . await ?)
0 commit comments