Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions tools/agent_tui/ui/timeout_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (u *UI) startCountdownTimer(
onTick func(remaining float64),
onTimeout func(),
) {
start := time.Now()
ticker := time.NewTicker(1 * time.Second)
secondsRemaining := int(duration.Seconds())

go func() {
defer ticker.Stop()
Expand All @@ -167,15 +167,14 @@ func (u *UI) startCountdownTimer(
case <-cancelChan:
return

case t := <-ticker.C:
elapsed := t.Sub(start)
if elapsed >= duration {
case <-ticker.C:
secondsRemaining--
if secondsRemaining <= 0 {
onTimeout()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're kind of mixing two different types of concurrency here. The ticker operates in a goroutine on wall-clock time, while the cancel comes from an event handler in the main loop.
So currently onTimeout() immediately exits the program as soon as the wall clock time has expired. But I think what it needs to do is post an event to the main loop (using app.QueueUpdate()) that checks whether the timeout has been cancelled, and only exits if it has not.
That way if user events get delayed past the wall-clock timeout, they will still be processed in order and serve to prevent the app from exiting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: ShowTimeoutDialog() calls Stop() directly.
ShowRendezvousIPTimeoutDialog(), which is the relevant one here, does use QueueUpdate(), but it doesn't check whether the timeout has already been cancelled by a previous event.

return
}

remaining := duration.Seconds() - elapsed.Seconds()
onTick(remaining)
onTick(float64(secondsRemaining))
Comment thread
zaneb marked this conversation as resolved.
}
}
}()
Expand Down