Skip to content

Commit 6f1054c

Browse files
author
virco
committed
fix possible huge sleep (stuck) in upload due to a race with timer and sleep time calculation underflow
1 parent c52f5ed commit 6f1054c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

pcallbacks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static void status_fill_formatted_str(pstatus_t *status, char *downloadstr, char
201201
}
202202
}
203203
}
204-
else
204+
else
205205
dw=cat_const(dw, "Everything Downloaded");
206206

207207
if (status->filestoupload){
@@ -226,7 +226,7 @@ static void status_fill_formatted_str(pstatus_t *status, char *downloadstr, char
226226
}
227227
}
228228
}
229-
else
229+
else
230230
up=cat_const(up, "Everything Uploaded");
231231

232232
assert(dw<downloadstr+MAX_STATUS_STR_LEN);
@@ -269,7 +269,7 @@ static void status_change_thread(void *ptr){
269269
(status_old.status == PSTATUS_PAUSED) ||
270270
(status_old.status == PSTATUS_OFFLINE) ) )
271271
)
272-
psync_run_ratelimited("Rebuild icons.", psync_rebuild_icons, 1, 1);
272+
psync_run_ratelimited("rebuild icons", psync_rebuild_icons, 1, 1);
273273
status_old = psync_status;
274274
pthread_mutex_unlock(&statusmutex);
275275
if (!psync_do_run)

pcompat.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,8 @@ void psync_rebuild_icons(){
31383138
void psync_rebuild_icons(){
31393139
if (!overlays_running)
31403140
return;
3141-
return;}
3141+
return;
3142+
}
31423143
#endif
31433144

31443145
int psync_invalidate_os_cache(const char *path){

pupload.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,14 +1007,17 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
10071007
else{
10081008
ret=0;
10091009
do {
1010-
psync_milisleep((psync_stat_mtime(&st)+PSYNC_UPLOAD_OLDER_THAN_SEC-ctime)*1000+500);
1011-
ctime=psync_timer_time();
1010+
if (ctime<psync_stat_mtime(&st))
1011+
ctime=psync_stat_mtime(&st);
1012+
if (psync_stat_mtime(&st)+PSYNC_UPLOAD_OLDER_THAN_SEC>ctime)
1013+
psync_milisleep((psync_stat_mtime(&st)+PSYNC_UPLOAD_OLDER_THAN_SEC-ctime)*1000+500);
10121014
if (psync_stat(localpath, &st)){
10131015
debug(D_NOTICE, "can not stat %s anymore, failing for now", localpath);
10141016
psync_free(localpath);
10151017
return -1;
10161018
}
1017-
} while (psync_stat_mtime(&st)>=psync_timer_time()-PSYNC_UPLOAD_OLDER_THAN_SEC && ++ret<=10);
1019+
ctime=psync_timer_time();
1020+
} while (psync_stat_mtime(&st)>=ctime-PSYNC_UPLOAD_OLDER_THAN_SEC && ++ret<=10);
10181021
if (ret==10){
10191022
debug(D_NOTICE, "file %s kept changing %d times, skipping for now", localpath, ret);
10201023
psync_free(localpath);

0 commit comments

Comments
 (0)