Fossil

Check-in [4db38487]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Go ahead and permanently remove the backoffice timeout mechanism, as it seems clear we will not have a use for it moving forward.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4db384875273f5375b62758f8d5e0bcf8fef15b81208450504044f10304388da
User & Date: drh 2018-08-08 23:59:54.071
Context
2018-08-09
03:35
Added point about multiple copies of each matching post in web search results to the forum.wiki doc. ... (check-in: 89ab99e3 user: wyoung tags: trunk)
2018-08-08
23:59
Go ahead and permanently remove the backoffice timeout mechanism, as it seems clear we will not have a use for it moving forward. ... (check-in: 4db38487 user: drh tags: trunk)
20:56
Disable backoffice timeouts. This is a temporary measure to avoid a horrible bug in which a timeout causes the email notification sending process to exit before recording the fact that notifications have already been sent, and thus causing the same notifications to be sent again on the next backoffice cycle, and so forth over and over and over. ... (check-in: 628d63c4 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/backoffice.c.
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
** Return a process id number for the current process
*/
static sqlite3_uint64 backofficeProcessId(void){
  return (sqlite3_uint64)GETPID();
}

#if 0 /* Disable the backoffice timeout for now */
/*
** Set an alarm to cause the process to exit after "x" seconds.  This
** prevents any kind of bug from keeping a backoffice process running
** indefinitely.
*/
static void backofficeSigalrmHandler(int x){
  fossil_panic("backoffice timeout (%d seconds)", x);
}
#if defined(_WIN32)
static void *threadHandle = NULL;
static void __stdcall backofficeWin32NoopApcProc(ULONG_PTR pArg){} /* NO-OP */
static void backofficeWin32ThreadCleanup(int bStrict){
  if( threadHandle!=NULL ){
    /* Queue no-op asynchronous procedure call to the sleeping
     * thread.  This will cause it to wake up with a non-zero
     * return value. */
    if( QueueUserAPC(backofficeWin32NoopApcProc, threadHandle, 0) ){
      /* Wait for the thread to wake up and then exit. */
      WaitForSingleObject(threadHandle, INFINITE);
    }else if(bStrict){
      DWORD dwLastError = GetLastError();
      fossil_errorlog(
        "backofficeWin32ThreadCleanup: QueueUserAPC failed, code %lu",
        dwLastError
      );
      if( !TerminateThread(threadHandle, dwLastError) ){
        dwLastError = GetLastError();
        fossil_panic(
          "backofficeWin32ThreadCleanup: TerminateThread failed, code %lu",
          dwLastError
        );
      }
    }
    CloseHandle(threadHandle);
    threadHandle = NULL;
  }else if(bStrict){
    fossil_panic(
      "backofficeWin32ThreadCleanup: no timeout thread handle"
    );
  }
}
static unsigned __stdcall backofficeWin32SigalrmThreadProc(
  void *pArg /* IN: Pointer to integer number of whole seconds. */
){
  int seconds = FOSSIL_PTR_TO_INT(pArg);
  if( SleepEx((DWORD)seconds * 1000, TRUE)==0 ){
    backofficeSigalrmHandler(seconds);
  }
  _endthreadex(0);
  return 0; /* NOT REACHED */
}
#endif
static void backofficeTimeout(int x){
#if defined(_WIN32)
  backofficeWin32ThreadCleanup(0);
  threadHandle = (void*)_beginthreadex(
    0, 0, backofficeWin32SigalrmThreadProc, FOSSIL_INT_TO_PTR(x), 0, 0
  );
#else
  signal(SIGALRM, backofficeSigalrmHandler);
  alarm(x);
#endif
}
#else  /* Real timeout (above) is disabled.  In its place is the following */
       /* stub routine */
static void backofficeTimeout(int x){ /* no-op */ }
#endif

/*
** COMMAND: test-process-id
**
** Usage: %fossil [--sleep N] PROCESS-ID ...
**
** Show the current process id, and also tell whether or not all other







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







303
304
305
306
307
308
309




































































310
311
312
313
314
315
316
/*
** Return a process id number for the current process
*/
static sqlite3_uint64 backofficeProcessId(void){
  return (sqlite3_uint64)GETPID();
}






































































/*
** COMMAND: test-process-id
**
** Usage: %fossil [--sleep N] PROCESS-ID ...
**
** Show the current process id, and also tell whether or not all other
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
  sqlite3_uint64 tmNow;
  sqlite3_uint64 idSelf;
  int lastWarning = 0;
  int warningDelay = 30;
  static int once = 0;

  backoffice_error_check_one(&once);
  backofficeTimeout(BKOFCE_LEASE_TIME*2);
  idSelf = backofficeProcessId();
  while(1){
    tmNow = time(0);
    db_begin_write();
    backofficeReadLease(&x);
    if( x.tmNext>=tmNow
     && x.idNext!=idSelf







<







429
430
431
432
433
434
435

436
437
438
439
440
441
442
  sqlite3_uint64 tmNow;
  sqlite3_uint64 idSelf;
  int lastWarning = 0;
  int warningDelay = 30;
  static int once = 0;

  backoffice_error_check_one(&once);

  idSelf = backofficeProcessId();
  while(1){
    tmNow = time(0);
    db_begin_write();
    backofficeReadLease(&x);
    if( x.tmNext>=tmNow
     && x.idNext!=idSelf