Skip to content

Commit d9e9d6a

Browse files
committed
Fix NTS time sync to properly wait for TLS handshake
chronyc waitsync with multiple retries completes too quickly (~3s) for NTS-KE TLS handshake. Replace with a loop that retries every 1s for up to 30s in secure_time mode. Revert dstack-prepare.sh to simple makestep since secure_time sync is handled in dstack-util.
1 parent dbdca25 commit d9e9d6a

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

basefiles/dstack-prepare.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,9 @@ mount_overlay /bin $OVERLAY_TMP
9595
mount_overlay /home $OVERLAY_TMP
9696

9797
# Make sure the system time is synchronized
98-
log "Waiting for time sync..."
99-
for i in $(seq 1 30); do
100-
if chronyc waitsync 1 0.2 0 0 2>/dev/null; then
101-
log "Time synchronized"
102-
break
103-
fi
104-
sleep 1
105-
done || log "Warning: time sync timed out"
98+
log "Syncing system time..."
99+
# Let the chronyd correct the system time immediately
100+
chronyc makestep
106101

107102
if ! [[ -e /dev/tdx_guest ]]; then
108103
modprobe tdx-guest

dstack-util/src/system_setup.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,18 @@ pub async fn cmd_sys_setup(args: SetupArgs) -> Result<()> {
708708
async fn do_sys_setup(stage0: Stage0<'_>) -> Result<()> {
709709
if stage0.shared.app_compose.secure_time {
710710
info!("Waiting for the system time to be synchronized");
711-
cmd! {
712-
chronyc waitsync 20 0.1;
711+
let mut synced = false;
712+
for i in 1..=30 {
713+
if cmd! { chronyc waitsync 1 0.2; }.is_ok() {
714+
synced = true;
715+
break;
716+
}
717+
info!("Time sync attempt {i}/30 failed, retrying...");
718+
tokio::time::sleep(Duration::from_secs(1)).await;
719+
}
720+
if !synced {
721+
bail!("Failed to sync system time after 30 attempts");
713722
}
714-
.context("Failed to sync system time")?;
715723
} else {
716724
info!("System time will be synchronized by chronyd in background");
717725
}

0 commit comments

Comments
 (0)