17
17
*/
18
18
19
19
use chrono:: { TimeDelta , Timelike } ;
20
+ use futures:: FutureExt ;
20
21
use std:: collections:: HashMap ;
21
22
use std:: future:: Future ;
22
23
use std:: panic:: AssertUnwindSafe ;
@@ -119,7 +120,7 @@ pub fn object_store_sync() -> (
119
120
info ! ( "Object store sync task started" ) ;
120
121
let mut inbox_rx = inbox_rx;
121
122
122
- let result = std :: panic :: catch_unwind ( AssertUnwindSafe ( || async move {
123
+ let result = tokio :: spawn ( async move {
123
124
let mut sync_interval = interval_at ( next_minute ( ) , STORAGE_UPLOAD_INTERVAL ) ;
124
125
125
126
loop {
@@ -153,11 +154,13 @@ pub fn object_store_sync() -> (
153
154
}
154
155
}
155
156
}
156
- } ) ) ;
157
+ } ) ;
157
158
158
- match result {
159
- Ok ( future) => {
160
- future. await ;
159
+ match AssertUnwindSafe ( result) . catch_unwind ( ) . await {
160
+ Ok ( join_result) => {
161
+ if let Err ( join_err) = join_result {
162
+ error ! ( "Panic in object store sync task: {join_err:?}" ) ;
163
+ }
161
164
}
162
165
Err ( panic_error) => {
163
166
error ! ( "Panic in object store sync task: {panic_error:?}" ) ;
@@ -184,12 +187,11 @@ pub fn local_sync() -> (
184
187
info ! ( "Local sync task started" ) ;
185
188
let mut inbox_rx = inbox_rx;
186
189
187
- let result = std :: panic :: catch_unwind ( AssertUnwindSafe ( || async move {
190
+ let result = tokio :: spawn ( async move {
188
191
let mut sync_interval = interval_at ( next_minute ( ) , LOCAL_SYNC_INTERVAL ) ;
189
192
190
193
loop {
191
194
select ! {
192
- // Spawns a flush+conversion task every `LOCAL_SYNC_INTERVAL` seconds
193
195
_ = sync_interval. tick( ) => {
194
196
// Monitor the duration of flush_and_convert execution
195
197
monitor_task_duration(
@@ -217,11 +219,13 @@ pub fn local_sync() -> (
217
219
}
218
220
}
219
221
}
220
- } ) ) ;
222
+ } ) ;
221
223
222
- match result {
223
- Ok ( future) => {
224
- future. await ;
224
+ match AssertUnwindSafe ( result) . catch_unwind ( ) . await {
225
+ Ok ( join_result) => {
226
+ if let Err ( join_err) = join_result {
227
+ error ! ( "Panic in local sync task: {join_err:?}" ) ;
228
+ }
225
229
}
226
230
Err ( panic_error) => {
227
231
error ! ( "Panic in local sync task: {panic_error:?}" ) ;
0 commit comments