This repository was archived by the owner on Aug 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-24
lines changed
node_framework/src/implementations/layers Expand file tree Collapse file tree 3 files changed +31
-24
lines changed Original file line number Diff line number Diff line change @@ -185,14 +185,19 @@ async fn run_tree(
185
185
if let Some ( api_config) = api_config {
186
186
let address = ( Ipv4Addr :: UNSPECIFIED , api_config. port ) . into ( ) ;
187
187
let tree_reader = metadata_calculator. tree_reader ( ) ;
188
- let stop_receiver = stop_receiver. clone ( ) ;
188
+ let mut stop_receiver = stop_receiver. clone ( ) ;
189
189
task_futures. push ( tokio:: spawn ( async move {
190
- tree_reader
191
- . wait ( )
192
- . await
193
- . context ( "Cannot initialize tree reader" ) ?
194
- . run_api_server ( address, stop_receiver)
195
- . await
190
+ if let Some ( reader) = tree_reader. wait ( ) . await {
191
+ reader. run_api_server ( address, stop_receiver) . await
192
+ } else {
193
+ // Tree is dropped before initialized, e.g. because the node is getting shut down.
194
+ // We don't want to treat this as an error since it could mask the real shutdown cause in logs etc.
195
+ tracing:: warn!(
196
+ "Tree is dropped before initialized, not starting the tree API server"
197
+ ) ;
198
+ stop_receiver. changed ( ) . await ?;
199
+ Ok ( ( ) )
200
+ }
196
201
} ) ) ;
197
202
}
198
203
Original file line number Diff line number Diff line change @@ -91,9 +91,10 @@ impl MerkleTreeHealthCheck {
91
91
let weak_reader = Arc :: < OnceCell < WeakAsyncTreeReader > > :: default ( ) ;
92
92
let weak_reader_for_task = weak_reader. clone ( ) ;
93
93
tokio:: spawn ( async move {
94
- weak_reader_for_task
95
- . set ( reader. wait ( ) . await . unwrap ( ) . downgrade ( ) )
96
- . ok ( ) ;
94
+ if let Some ( reader) = reader. wait ( ) . await {
95
+ weak_reader_for_task. set ( reader. downgrade ( ) ) . ok ( ) ;
96
+ }
97
+ // Otherwise, the tree is dropped before getting initialized; this is not an error in this context.
97
98
} ) ;
98
99
99
100
Self {
@@ -393,16 +394,14 @@ impl LazyAsyncTreeReader {
393
394
self . 0 . borrow ( ) . clone ( )
394
395
}
395
396
396
- /// Waits until the tree is initialized and returns a reader for it.
397
- pub async fn wait ( mut self ) -> anyhow:: Result < AsyncTreeReader > {
397
+ /// Waits until the tree is initialized and returns a reader for it. If the tree is dropped before
398
+ /// getting initialized, returns `None`.
399
+ pub async fn wait ( mut self ) -> Option < AsyncTreeReader > {
398
400
loop {
399
401
if let Some ( reader) = self . 0 . borrow ( ) . clone ( ) {
400
- break Ok ( reader) ;
402
+ break Some ( reader) ;
401
403
}
402
- self . 0
403
- . changed ( )
404
- . await
405
- . context ( "Tree dropped without getting ready; not resolving tree reader" ) ?;
404
+ self . 0 . changed ( ) . await . ok ( ) ?;
406
405
}
407
406
}
408
407
}
Original file line number Diff line number Diff line change @@ -162,13 +162,16 @@ impl Task for TreeApiTask {
162
162
"tree_api" . into ( )
163
163
}
164
164
165
- async fn run ( self : Box < Self > , stop_receiver : StopReceiver ) -> anyhow:: Result < ( ) > {
166
- self . tree_reader
167
- . wait ( )
168
- . await
169
- . context ( "Cannot initialize tree reader" ) ?
170
- . run_api_server ( self . bind_addr , stop_receiver. 0 )
171
- . await
165
+ async fn run ( self : Box < Self > , mut stop_receiver : StopReceiver ) -> anyhow:: Result < ( ) > {
166
+ if let Some ( reader) = self . tree_reader . wait ( ) . await {
167
+ reader. run_api_server ( self . bind_addr , stop_receiver. 0 ) . await
168
+ } else {
169
+ // Tree is dropped before initialized, e.g. because the node is getting shut down.
170
+ // We don't want to treat this as an error since it could mask the real shutdown cause in logs etc.
171
+ tracing:: warn!( "Tree is dropped before initialized, not starting the tree API server" ) ;
172
+ stop_receiver. 0 . changed ( ) . await ?;
173
+ Ok ( ( ) )
174
+ }
172
175
}
173
176
}
174
177
You can’t perform that action at this time.
0 commit comments