@@ -28,6 +28,8 @@ type Task struct {
2828 InstallingApps sync.Map
2929 InstallAppQueue chan TaskItem
3030 chExitQueue chan bool
31+ queueStartOnce sync.Once
32+ queueStopOnce sync.Once
3133 InvalidAccounts map [string ]bool
3234 // RefreshingDevices prevents concurrent refresh operations for the same device UDID
3335 RefreshingDevices sync.Map
@@ -98,7 +100,10 @@ func new() *Task {
98100
99101func (t * Task ) RunSchedule () error {
100102 if t .c != nil {
101- t .Stop ()
103+ // Updating cron settings must not restart the install worker.
104+ // That worker can still be in its initial 30-second usbmuxd wait.
105+ <- t .c .Stop ().Done ()
106+ t .c = nil
102107 }
103108
104109 if _ , err := cron .ParseStandard (app .Settings .Task .CrodTime ); err != nil {
@@ -151,13 +156,20 @@ func (t *Task) Start() {
151156 }
152157 })
153158
154- go t .runQueue ()
159+ // The installation queue belongs to the Task lifetime, not to the
160+ // cron schedule. Repeated settings updates must never spawn new workers.
161+ t .queueStartOnce .Do (func () { go t .runQueue () })
155162}
156163
164+ // Stop shuts down the Task. RunSchedule only replaces the cron schedule.
157165func (t * Task ) Stop () {
158- t .chExitQueue <- true
159- <- t .c .Stop ().Done ()
160- t .c = nil
166+ // Closing is non-blocking even when runQueue is still waiting for
167+ // usbmuxd, and the once guard makes repeated Stop calls safe.
168+ t .queueStopOnce .Do (func () { close (t .chExitQueue ) })
169+ if t .c != nil {
170+ <- t .c .Stop ().Done ()
171+ t .c = nil
172+ }
161173}
162174
163175// removeStaleTempFiles removes the staged files abandoned in the upload
0 commit comments