@@ -54,10 +54,6 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
5454 // The route is already in a failed state, it will be retried later
5555 if ( this . routeInFailedState . has ( msg . MessageDeduplicationId ) ) return ;
5656
57- // If the last success is newer than the last modified, it's likely that the regional cache is out of date
58- // We don't need to revalidate in this case
59- if ( this . checkSyncTable ( msg ) ) return ;
60-
6157 if ( this . ongoingRevalidations . size >= MAX_REVALIDATION_BY_DURABLE_OBJECT ) {
6258 const ongoingRevalidations = this . ongoingRevalidations . values ( ) ;
6359 // When there is more than the max revalidations, we block concurrency until one of the revalidations finishes
@@ -82,7 +78,6 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
8278 previewModeId,
8379 } = msg ;
8480 const protocol = host . includes ( "localhost" ) ? "http" : "https" ;
85- console . log ( 'previewModeId' , previewModeId ) ;
8681
8782 const response = await this . service . fetch ( `${ protocol } ://${ host } ${ url } ` , {
8883 method : "HEAD" ,
@@ -94,12 +89,15 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
9489 } ) ;
9590 // Now we need to handle errors from the fetch
9691 if ( response . status === 200 && response . headers . get ( "x-nextjs-cache" ) !== "REVALIDATED" ) {
97- // Something is very wrong here, it means that either the page is not ISR/SSG (and we shouldn't be here) or the `x-prerender-revalidate` header is not correct (and it should not happen either)
92+ // TODO: when restoring from the failed state during a new deployment, previewModeId will be different and we'll be in this case. Figure out how to handle this.
93+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
9894 throw new FatalError (
9995 `The revalidation for ${ host } ${ url } cannot be done. This error should never happen.`
10096 ) ;
10197 } else if ( response . status === 404 ) {
10298 // The page is not found, we should not revalidate it
99+ // We remove the route from the failed state because it might be expected (i.e. a route that was deleted)
100+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
103101 throw new IgnorableError (
104102 `The revalidation for ${ host } ${ url } cannot be done because the page is not found. It's either expected or an error in user code itself`
105103 ) ;
@@ -112,15 +110,14 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
112110 } else if ( response . status !== 200 ) {
113111 // TODO: check if we need to handle cloudflare specific status codes/errors
114112 // An unknown error occurred, most likely from something in user code like missing auth in the middleware
113+
114+ // We probably want to retry in this case as well
115+ await this . addToFailedState ( msg ) ;
116+
115117 throw new RecoverableError ( `An unknown error occurred while revalidating ${ host } ${ url } ` ) ;
116118 }
117- // Everything went well, we can update the sync table
118- // We use unixepoch here because without IO the date doesn't change and it will make the e2e tests fail
119- this . sql . exec (
120- "INSERT OR REPLACE INTO sync (id, lastSuccess) VALUES (?, unixepoch())" ,
121- // We cannot use the deduplication id because it's not unique per route - every time a route is revalidated, the deduplication id is different.
122- `${ host } ${ url } `
123- ) ;
119+ // If everything went well, we can remove the route from the failed state
120+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
124121 } catch ( e ) {
125122 // Do we want to propagate the error to the calling worker?
126123 if ( ! isOpenNextError ( e ) ) {
@@ -145,6 +142,7 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
145142 const allEventsToRetry = nextEventToRetry ? [ nextEventToRetry , ...expiredEvents ] : expiredEvents ;
146143 for ( const event of allEventsToRetry ) {
147144 await this . executeRevalidation ( event . msg ) ;
145+ this . routeInFailedState . delete ( event . msg . MessageDeduplicationId ) ;
148146 }
149147 }
150148
0 commit comments