@@ -44,18 +44,30 @@ struct PreviewRdParams {
44
44
pub fn start ( target_port : u16 ) -> anyhow:: Result < u16 > {
45
45
let source_port = HelpProxy :: get_os_assigned_port ( ) ?;
46
46
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 ( ( ) )
52
65
} ) ;
53
66
54
67
Ok ( source_port)
55
68
}
56
69
57
70
// The help proxy main entry point.
58
- #[ tokio:: main]
59
71
async fn task ( source_port : u16 , target_port : u16 ) -> anyhow:: Result < ( ) > {
60
72
// Create the help proxy.
61
73
let help_proxy = HelpProxy :: new ( source_port, target_port) ?;
@@ -101,7 +113,8 @@ impl HelpProxy {
101
113
. service ( preview_img)
102
114
. default_service ( web:: to ( proxy_request) )
103
115
} )
104
- . bind ( ( "127.0.0.1" , self . source_port ) ) ?;
116
+ . bind ( ( "127.0.0.1" , self . source_port ) ) ?
117
+ . workers ( 1 ) ;
105
118
106
119
// Run the server.
107
120
Ok ( server. run ( ) . await ?)
0 commit comments