Fossil

Check-in [f525b6d5]
Login

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

Overview
Comment:Improved SQL logging after SIGPIPE. Exponential backoff in the warnings issued when the backoffice process misses its deadline.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:f525b6d5e9dcb775a931aa2949684d9b02ce57f959fa3aff4c9982f4be2a5699
User & Date: drh 2018-07-19 16:27:51
Context
2018-07-19
17:22
The email_auto_exec property is removed. The routine that sends alert emails is renamed to email_backoffice() and it is configured to always auto-run. check-in: ada7ecde user: drh tags: trunk
16:27
Improved SQL logging after SIGPIPE. Exponential backoff in the warnings issued when the backoffice process misses its deadline. check-in: f525b6d5 user: drh tags: trunk
15:58
At the end of CGI processing, close the output pipe before starting backoffice processing, in order to let higher levels know that the CGI is finished. check-in: a32a92d2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/backoffice.c.

   182    182   ** routine enters a loop to do background work periodically.
   183    183   */
   184    184   void backoffice_run(void){
   185    185     Lease x;
   186    186     sqlite3_uint64 tmNow;
   187    187     sqlite3_uint64 idSelf;
   188    188     int lastWarning = 0;
          189  +  int warningDelay = 30;
   189    190   
   190    191     if( g.db==0 ){
   191    192       fossil_panic("database not open for backoffice processing");
   192    193     }
   193    194     if( db_transaction_nesting_depth()!=0 ){
   194    195       fossil_panic("transaction %s not closed prior to backoffice processing",
   195    196                    db_transaction_start_point());
................................................................................
   228    229       x.idNext = idSelf;
   229    230       x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
   230    231       backofficeWriteLease(&x);
   231    232       db_end_transaction(0);
   232    233       if( x.tmCurrent >= tmNow ){
   233    234         sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
   234    235       }else{
   235         -      if( lastWarning+30 < tmNow ){
          236  +      if( lastWarning+warningDelay < tmNow ){
   236    237           fossil_warning(
   237    238              "backoffice process %lld still running after %d seconds",
   238    239              x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent));
   239    240           lastWarning = tmNow;
          241  +        warningDelay *= 2;
   240    242         }
   241    243         sqlite3_sleep(1000);
   242    244       }
   243    245     }
   244    246     return;
   245    247   }
   246    248   

Changes to src/db.c.

  1884   1884     }
  1885   1885     g.repositoryOpen = 0;
  1886   1886     g.localOpen = 0;
  1887   1887     assert( g.dbConfig==0 );
  1888   1888     assert( g.zConfigDbName==0 );
  1889   1889   }
  1890   1890   
         1891  +/*
         1892  +** Close the database as quickly as possible without unnecessary processing.
         1893  +*/
         1894  +void db_panic_close(void){
         1895  +  if( g.db ){
         1896  +    int rc;
         1897  +    sqlite3_wal_checkpoint(g.db, 0);
         1898  +    rc = sqlite3_close(g.db);
         1899  +    if( g.fSqlTrace ) fossil_trace("-- sqlite3_close(%d)\n", rc);
         1900  +  }
         1901  +  g.db = 0;
         1902  +  g.repositoryOpen = 0;
         1903  +  g.localOpen = 0;
         1904  +}
  1891   1905   
  1892   1906   /*
  1893   1907   ** Create a new empty repository database with the given name.
  1894   1908   **
  1895   1909   ** Only the schema is initialized.  The required VAR tables entries
  1896   1910   ** are not set by this routine and must be set separately in order
  1897   1911   ** to make the new file a valid database.

Changes to src/main.c.

  1446   1446   /*
  1447   1447   ** Called if a server gets a SIGPIPE.  This often happens when a client
  1448   1448   ** webbrowser opens a connection but never sends the HTTP request
  1449   1449   */
  1450   1450   void sigpipe_handler(int x){
  1451   1451   #ifndef _WIN32
  1452   1452     if( g.fAnyTrace ){
  1453         -    fprintf(stderr,"/**** sigpipe received by subprocess %d ****\n", getpid());
         1453  +    fprintf(stderr,"/***** sigpipe received by subprocess %d ****\n", getpid());
  1454   1454     }
  1455   1455   #endif
  1456         -  fossil_exit(1);
         1456  +  db_panic_close();
         1457  +  exit(1);
  1457   1458   }
  1458   1459   
  1459   1460   /*
  1460   1461   ** Preconditions:
  1461   1462   **
  1462   1463   **  * Environment variables are set up according to the CGI standard.
  1463   1464   **