Fossil SCM
Fix a corner case in ticket_rebuild() in which an untimely error could cause all tickets to seemingly (but only seemingly) disappear. Addresses [forum:4f3f572abff6b8c1|bug report 2026-10-31T15:16:27Z]. This solution was suggested by Dan Mestas and its included documentation is my distillation of Dan's more thorough analysis.
Commit
f815d4820d389dde3447912e0a33a09c1814b4ee0769b1cb41f2f8bcde11cdaa
Parent
29ffb70a25e6781…
1 file changed
+16
-2
+16
-2
| --- src/tkt.c | ||
| +++ src/tkt.c | ||
| @@ -663,12 +663,26 @@ | ||
| 663 | 663 | ** Repopulate the TICKET and TICKETCHNG tables from scratch using all |
| 664 | 664 | ** available ticket artifacts. |
| 665 | 665 | */ |
| 666 | 666 | void ticket_rebuild(void){ |
| 667 | 667 | Stmt q; |
| 668 | - ticket_create_table(1); | |
| 669 | - db_begin_transaction(); | |
| 668 | + if( db_database_slot("repository")==0 ){ | |
| 669 | + /* forum:4f3f572abff6b8c1: to avoid losing all of the tickets if the | |
| 670 | + ** current operation fails at some point after this call, we need | |
| 671 | + ** to start the transaction before dropping the ticket tables. | |
| 672 | + ** | |
| 673 | + ** Claude was able to reproduce that report reliably using a | |
| 674 | + ** fossil server running with --max-latency 2 and 40k tickets. */ | |
| 675 | + db_begin_transaction(); | |
| 676 | + ticket_create_table(0); | |
| 677 | + }else{ | |
| 678 | + /* A checkout: the tickets go into the associated repo db via | |
| 679 | + ** ticket_create_table(). Delay transaction start until that | |
| 680 | + ** succeeds. */ | |
| 681 | + ticket_create_table(1); | |
| 682 | + db_begin_transaction(); | |
| 683 | + } | |
| 670 | 684 | db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'"); |
| 671 | 685 | while( db_step(&q)==SQLITE_ROW ){ |
| 672 | 686 | const char *zName = db_column_text(&q, 0); |
| 673 | 687 | int len; |
| 674 | 688 | zName += 4; |
| 675 | 689 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -663,12 +663,26 @@ | |
| 663 | ** Repopulate the TICKET and TICKETCHNG tables from scratch using all |
| 664 | ** available ticket artifacts. |
| 665 | */ |
| 666 | void ticket_rebuild(void){ |
| 667 | Stmt q; |
| 668 | ticket_create_table(1); |
| 669 | db_begin_transaction(); |
| 670 | db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'"); |
| 671 | while( db_step(&q)==SQLITE_ROW ){ |
| 672 | const char *zName = db_column_text(&q, 0); |
| 673 | int len; |
| 674 | zName += 4; |
| 675 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -663,12 +663,26 @@ | |
| 663 | ** Repopulate the TICKET and TICKETCHNG tables from scratch using all |
| 664 | ** available ticket artifacts. |
| 665 | */ |
| 666 | void ticket_rebuild(void){ |
| 667 | Stmt q; |
| 668 | if( db_database_slot("repository")==0 ){ |
| 669 | /* forum:4f3f572abff6b8c1: to avoid losing all of the tickets if the |
| 670 | ** current operation fails at some point after this call, we need |
| 671 | ** to start the transaction before dropping the ticket tables. |
| 672 | ** |
| 673 | ** Claude was able to reproduce that report reliably using a |
| 674 | ** fossil server running with --max-latency 2 and 40k tickets. */ |
| 675 | db_begin_transaction(); |
| 676 | ticket_create_table(0); |
| 677 | }else{ |
| 678 | /* A checkout: the tickets go into the associated repo db via |
| 679 | ** ticket_create_table(). Delay transaction start until that |
| 680 | ** succeeds. */ |
| 681 | ticket_create_table(1); |
| 682 | db_begin_transaction(); |
| 683 | } |
| 684 | db_prepare(&q,"SELECT tagname FROM tag WHERE tagname GLOB 'tkt-*'"); |
| 685 | while( db_step(&q)==SQLITE_ROW ){ |
| 686 | const char *zName = db_column_text(&q, 0); |
| 687 | int len; |
| 688 | zName += 4; |
| 689 |