Fossil SCM
When sync triggers an OOM, reformulate the error message into a sync message rather than emitting HTML. This is intended to address [forum:c15ec806c36935b5|bug report 2026-11-13T14:45:54Z] but it may turn out that this was a separate issue.
Commit
4455100420ac18b13fc05db1097b055d73b4de091f52e986f5527976ea21abeb
Parent
25193762094ef46…
3 files changed
+4
+12
-1
+7
-2
M
src/db.c
+4
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -122,13 +122,17 @@ | ||
| 122 | 122 | json_err( 0, z, 1 ); |
| 123 | 123 | } |
| 124 | 124 | else |
| 125 | 125 | #endif /* FOSSIL_ENABLE_JSON */ |
| 126 | 126 | if( g.xferPanic && g.cgiOutput==1 ){ |
| 127 | + /* Report the error to the sync client here, before the additions | |
| 128 | + ** below which may reveal server filesystem paths. Mark the output | |
| 129 | + ** as done so that fossil_fatal() does not send a second reply. */ | |
| 127 | 130 | cgi_reset_content(); |
| 128 | 131 | @ error Database\serror:\s%F(z) |
| 129 | 132 | cgi_reply(); |
| 133 | + g.cgiOutput = 2; | |
| 130 | 134 | } |
| 131 | 135 | if( strstr(z,"attempt to write a readonly database") ){ |
| 132 | 136 | static const char *azDbNames[] = { "repository", "localdb", "configdb" }; |
| 133 | 137 | int i; |
| 134 | 138 | for(i=0; i<3; i++){ |
| 135 | 139 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -122,13 +122,17 @@ | |
| 122 | json_err( 0, z, 1 ); |
| 123 | } |
| 124 | else |
| 125 | #endif /* FOSSIL_ENABLE_JSON */ |
| 126 | if( g.xferPanic && g.cgiOutput==1 ){ |
| 127 | cgi_reset_content(); |
| 128 | @ error Database\serror:\s%F(z) |
| 129 | cgi_reply(); |
| 130 | } |
| 131 | if( strstr(z,"attempt to write a readonly database") ){ |
| 132 | static const char *azDbNames[] = { "repository", "localdb", "configdb" }; |
| 133 | int i; |
| 134 | for(i=0; i<3; i++){ |
| 135 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -122,13 +122,17 @@ | |
| 122 | json_err( 0, z, 1 ); |
| 123 | } |
| 124 | else |
| 125 | #endif /* FOSSIL_ENABLE_JSON */ |
| 126 | if( g.xferPanic && g.cgiOutput==1 ){ |
| 127 | /* Report the error to the sync client here, before the additions |
| 128 | ** below which may reveal server filesystem paths. Mark the output |
| 129 | ** as done so that fossil_fatal() does not send a second reply. */ |
| 130 | cgi_reset_content(); |
| 131 | @ error Database\serror:\s%F(z) |
| 132 | cgi_reply(); |
| 133 | g.cgiOutput = 2; |
| 134 | } |
| 135 | if( strstr(z,"attempt to write a readonly database") ){ |
| 136 | static const char *azDbNames[] = { "repository", "localdb", "configdb" }; |
| 137 | int i; |
| 138 | for(i=0; i<3; i++){ |
| 139 |
+12
-1
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -1154,11 +1154,22 @@ | ||
| 1154 | 1154 | cgi_reply(); |
| 1155 | 1155 | } |
| 1156 | 1156 | } |
| 1157 | 1157 | else |
| 1158 | 1158 | #endif |
| 1159 | - if( g.cgiOutput==1 && g.db ){ | |
| 1159 | + if( g.xferPanic && g.cgiOutput==1 ){ | |
| 1160 | + /* An error while serving /xfer. Report it as a sync-protocol | |
| 1161 | + ** "error" card rather than an HTML page so that the client can | |
| 1162 | + ** show the actual message. The client does not parse the body | |
| 1163 | + ** of a non-200 reply, so the status code is left alone. The | |
| 1164 | + ** content type is likewise left as /xfer set it, so that the | |
| 1165 | + ** reply is compressed (or not) the way the client expects. */ | |
| 1166 | + g.cgiOutput = 2; | |
| 1167 | + cgi_reset_content(); | |
| 1168 | + @ error %F(z) | |
| 1169 | + cgi_reply(); | |
| 1170 | + }else if( g.cgiOutput==1 && g.db ){ | |
| 1160 | 1171 | g.cgiOutput = 2; |
| 1161 | 1172 | cgi_reset_content(); |
| 1162 | 1173 | cgi_set_content_type("text/html"); |
| 1163 | 1174 | if( g.zLogin!=0 ){ |
| 1164 | 1175 | style_set_current_feature("error"); |
| 1165 | 1176 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -1154,11 +1154,22 @@ | |
| 1154 | cgi_reply(); |
| 1155 | } |
| 1156 | } |
| 1157 | else |
| 1158 | #endif |
| 1159 | if( g.cgiOutput==1 && g.db ){ |
| 1160 | g.cgiOutput = 2; |
| 1161 | cgi_reset_content(); |
| 1162 | cgi_set_content_type("text/html"); |
| 1163 | if( g.zLogin!=0 ){ |
| 1164 | style_set_current_feature("error"); |
| 1165 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -1154,11 +1154,22 @@ | |
| 1154 | cgi_reply(); |
| 1155 | } |
| 1156 | } |
| 1157 | else |
| 1158 | #endif |
| 1159 | if( g.xferPanic && g.cgiOutput==1 ){ |
| 1160 | /* An error while serving /xfer. Report it as a sync-protocol |
| 1161 | ** "error" card rather than an HTML page so that the client can |
| 1162 | ** show the actual message. The client does not parse the body |
| 1163 | ** of a non-200 reply, so the status code is left alone. The |
| 1164 | ** content type is likewise left as /xfer set it, so that the |
| 1165 | ** reply is compressed (or not) the way the client expects. */ |
| 1166 | g.cgiOutput = 2; |
| 1167 | cgi_reset_content(); |
| 1168 | @ error %F(z) |
| 1169 | cgi_reply(); |
| 1170 | }else if( g.cgiOutput==1 && g.db ){ |
| 1171 | g.cgiOutput = 2; |
| 1172 | cgi_reset_content(); |
| 1173 | cgi_set_content_type("text/html"); |
| 1174 | if( g.zLogin!=0 ){ |
| 1175 | style_set_current_feature("error"); |
| 1176 |
+7
-2
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -2958,11 +2958,14 @@ | ||
| 2958 | 2958 | ** Except, when cloning we will sometimes get an error on the |
| 2959 | 2959 | ** first message exchange because the project-code is unknown |
| 2960 | 2960 | ** and so the login card on the request was invalid. The project-code |
| 2961 | 2961 | ** is returned in the reply before the error card, so second and |
| 2962 | 2962 | ** subsequent messages should be OK. Nevertheless, we need to ignore |
| 2963 | - ** the error card on the first message of a clone. | |
| 2963 | + ** login and authorization errors on the first message of a clone. | |
| 2964 | + ** Any other error on that first message (for example, the server | |
| 2965 | + ** running out of memory) is reported, as otherwise the clone would | |
| 2966 | + ** carry on and silently produce an empty repository. | |
| 2964 | 2967 | ** |
| 2965 | 2968 | ** Also ignore "not authorized to write" errors if this is an |
| 2966 | 2969 | ** autopush following a commit. |
| 2967 | 2970 | */ |
| 2968 | 2971 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| @@ -2970,11 +2973,13 @@ | ||
| 2970 | 2973 | defossilize(zMsg); |
| 2971 | 2974 | if( (syncFlags & SYNC_IFABLE)!=0 |
| 2972 | 2975 | && sqlite3_strlike("%not authorized to write%",zMsg,0)==0 ){ |
| 2973 | 2976 | autopushFailed = 1; |
| 2974 | 2977 | nErr++; |
| 2975 | - }else if( (syncFlags & SYNC_CLONE)==0 || nCycle>0 ){ | |
| 2978 | + }else if( (syncFlags & SYNC_CLONE)==0 || nCycle>0 | |
| 2979 | + || (sqlite3_strlike("not authorized%",zMsg,0)!=0 | |
| 2980 | + && sqlite3_strlike("login failed%",zMsg,0)!=0) ){ | |
| 2976 | 2981 | fossil_force_newline(); |
| 2977 | 2982 | fossil_print("Error: %s\n", zMsg); |
| 2978 | 2983 | blob_appendf(&xfer.err, "server says: %s\n", zMsg); |
| 2979 | 2984 | nErr++; |
| 2980 | 2985 | break; |
| 2981 | 2986 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -2958,11 +2958,14 @@ | |
| 2958 | ** Except, when cloning we will sometimes get an error on the |
| 2959 | ** first message exchange because the project-code is unknown |
| 2960 | ** and so the login card on the request was invalid. The project-code |
| 2961 | ** is returned in the reply before the error card, so second and |
| 2962 | ** subsequent messages should be OK. Nevertheless, we need to ignore |
| 2963 | ** the error card on the first message of a clone. |
| 2964 | ** |
| 2965 | ** Also ignore "not authorized to write" errors if this is an |
| 2966 | ** autopush following a commit. |
| 2967 | */ |
| 2968 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| @@ -2970,11 +2973,13 @@ | |
| 2970 | defossilize(zMsg); |
| 2971 | if( (syncFlags & SYNC_IFABLE)!=0 |
| 2972 | && sqlite3_strlike("%not authorized to write%",zMsg,0)==0 ){ |
| 2973 | autopushFailed = 1; |
| 2974 | nErr++; |
| 2975 | }else if( (syncFlags & SYNC_CLONE)==0 || nCycle>0 ){ |
| 2976 | fossil_force_newline(); |
| 2977 | fossil_print("Error: %s\n", zMsg); |
| 2978 | blob_appendf(&xfer.err, "server says: %s\n", zMsg); |
| 2979 | nErr++; |
| 2980 | break; |
| 2981 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -2958,11 +2958,14 @@ | |
| 2958 | ** Except, when cloning we will sometimes get an error on the |
| 2959 | ** first message exchange because the project-code is unknown |
| 2960 | ** and so the login card on the request was invalid. The project-code |
| 2961 | ** is returned in the reply before the error card, so second and |
| 2962 | ** subsequent messages should be OK. Nevertheless, we need to ignore |
| 2963 | ** login and authorization errors on the first message of a clone. |
| 2964 | ** Any other error on that first message (for example, the server |
| 2965 | ** running out of memory) is reported, as otherwise the clone would |
| 2966 | ** carry on and silently produce an empty repository. |
| 2967 | ** |
| 2968 | ** Also ignore "not authorized to write" errors if this is an |
| 2969 | ** autopush following a commit. |
| 2970 | */ |
| 2971 | if( blob_eq(&xfer.aToken[0],"error") && xfer.nToken==2 ){ |
| @@ -2970,11 +2973,13 @@ | |
| 2973 | defossilize(zMsg); |
| 2974 | if( (syncFlags & SYNC_IFABLE)!=0 |
| 2975 | && sqlite3_strlike("%not authorized to write%",zMsg,0)==0 ){ |
| 2976 | autopushFailed = 1; |
| 2977 | nErr++; |
| 2978 | }else if( (syncFlags & SYNC_CLONE)==0 || nCycle>0 |
| 2979 | || (sqlite3_strlike("not authorized%",zMsg,0)!=0 |
| 2980 | && sqlite3_strlike("login failed%",zMsg,0)!=0) ){ |
| 2981 | fossil_force_newline(); |
| 2982 | fossil_print("Error: %s\n", zMsg); |
| 2983 | blob_appendf(&xfer.err, "server says: %s\n", zMsg); |
| 2984 | nErr++; |
| 2985 | break; |
| 2986 |