@@ -128,60 +128,62 @@ pub(crate) async fn execute() -> Result<()> {
128128
129129 let env = envs. get_or_create ( 1 ) ;
130130
131- let distributed_state = if let ( Some ( node_address) , Some ( control_address) ) =
132- ( args. value_of ( "node" ) , args. value_of ( "control" ) )
133- {
134- // TODO unwrap, better message
135- let node_address = node_address. parse ( ) . unwrap ( ) ;
136- let node_name = Uuid :: new_v4 ( ) . to_string ( ) ;
137- let control_address = control_address. parse ( ) . unwrap ( ) ;
138- let ca_cert = lunatic_distributed:: distributed:: server:: root_cert (
139- args. is_present ( "test_ca" ) ,
140- args. value_of ( "ca_cert" ) ,
141- )
142- . unwrap ( ) ;
143- let node_cert =
144- lunatic_distributed:: distributed:: server:: gen_node_cert ( & node_name) . unwrap ( ) ;
131+ let ( distributed_state, control_client, node_id) =
132+ if let ( Some ( node_address) , Some ( control_address) ) =
133+ ( args. value_of ( "node" ) , args. value_of ( "control" ) )
134+ {
135+ // TODO unwrap, better message
136+ let node_address = node_address. parse ( ) . unwrap ( ) ;
137+ let node_name = Uuid :: new_v4 ( ) . to_string ( ) ;
138+ let control_address = control_address. parse ( ) . unwrap ( ) ;
139+ let ca_cert = lunatic_distributed:: distributed:: server:: root_cert (
140+ args. is_present ( "test_ca" ) ,
141+ args. value_of ( "ca_cert" ) ,
142+ )
143+ . unwrap ( ) ;
144+ let node_cert =
145+ lunatic_distributed:: distributed:: server:: gen_node_cert ( & node_name) . unwrap ( ) ;
145146
146- let quic_client = quic:: new_quic_client ( & ca_cert) . unwrap ( ) ;
147+ let quic_client = quic:: new_quic_client ( & ca_cert) . unwrap ( ) ;
147148
148- let ( node_id, control_client, signed_cert_pem) = control:: Client :: register (
149- node_address,
150- node_name. to_string ( ) ,
151- control_address,
152- quic_client. clone ( ) ,
153- node_cert. serialize_request_pem ( ) . unwrap ( ) ,
154- )
155- . await ?;
149+ let ( node_id, control_client, signed_cert_pem) = control:: Client :: register (
150+ node_address,
151+ node_name. to_string ( ) ,
152+ control_address,
153+ quic_client. clone ( ) ,
154+ node_cert. serialize_request_pem ( ) . unwrap ( ) ,
155+ )
156+ . await ?;
156157
157- let distributed_client =
158- distributed:: Client :: new ( node_id, control_client. clone ( ) , quic_client. clone ( ) ) . await ?;
158+ let distributed_client =
159+ distributed:: Client :: new ( node_id, control_client. clone ( ) , quic_client. clone ( ) )
160+ . await ?;
159161
160- let dist = lunatic_distributed:: DistributedProcessState :: new (
161- node_id,
162- control_client. clone ( ) ,
163- distributed_client,
164- )
165- . await ?;
166-
167- tokio:: task:: spawn ( lunatic_distributed:: distributed:: server:: node_server (
168- ServerCtx {
169- envs,
170- modules : Modules :: < DefaultProcessState > :: default ( ) ,
171- distributed : dist. clone ( ) ,
172- runtime : runtime. clone ( ) ,
173- } ,
174- node_address,
175- signed_cert_pem,
176- node_cert. serialize_private_key_pem ( ) ,
177- ) ) ;
178-
179- log:: info!( "Registration successful, node id {}" , node_id) ;
180-
181- Some ( dist)
182- } else {
183- None
184- } ;
162+ let dist = lunatic_distributed:: DistributedProcessState :: new (
163+ node_id,
164+ control_client. clone ( ) ,
165+ distributed_client,
166+ )
167+ . await ?;
168+
169+ tokio:: task:: spawn ( lunatic_distributed:: distributed:: server:: node_server (
170+ ServerCtx {
171+ envs,
172+ modules : Modules :: < DefaultProcessState > :: default ( ) ,
173+ distributed : dist. clone ( ) ,
174+ runtime : runtime. clone ( ) ,
175+ } ,
176+ node_address,
177+ signed_cert_pem,
178+ node_cert. serialize_private_key_pem ( ) ,
179+ ) ) ;
180+
181+ log:: info!( "Registration successful, node id {}" , node_id) ;
182+
183+ ( Some ( dist) , Some ( control_client ) , Some ( node_id ) )
184+ } else {
185+ ( None , None , None )
186+ } ;
185187
186188 let mut config = DefaultProcessConfig :: default ( ) ;
187189 // Allow initial process to compile modules, create configurations and spawn sub-processes
@@ -244,7 +246,14 @@ pub(crate) async fn execute() -> Result<()> {
244246 path. to_string_lossy( )
245247 ) ) ?;
246248 // Wait on the main process to finish
247- task. await . map ( |_| ( ) ) . map_err ( |e| anyhow ! ( e. to_string( ) ) )
249+ let result = task. await . map ( |_| ( ) ) . map_err ( |e| anyhow ! ( e. to_string( ) ) ) ;
250+
251+ // Until we refactor registration and reconnect authentication, send node id explicitly
252+ if let ( Some ( ctrl) , Some ( node_id) ) = ( control_client, node_id) {
253+ ctrl. deregister ( node_id) . await ;
254+ }
255+
256+ result
248257 } else {
249258 // Block forever
250259 let ( _sender, mut receiver) = channel :: < ( ) > ( 1 ) ;
0 commit comments