@@ -55,10 +55,6 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
5555 // The route is already in a failed state, it will be retried later
5656 if ( this . routeInFailedState . has ( msg . MessageDeduplicationId ) ) return ;
5757
58- // If the last success is newer than the last modified, it's likely that the regional cache is out of date
59- // We don't need to revalidate in this case
60- if ( this . checkSyncTable ( msg ) ) return ;
61-
6258 if ( this . ongoingRevalidations . size >= MAX_REVALIDATION_BY_DURABLE_OBJECT ) {
6359 const ongoingRevalidations = this . ongoingRevalidations . values ( ) ;
6460 // When there is more than the max revalidations, we block concurrency until one of the revalidations finishes
@@ -83,7 +79,6 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
8379 previewModeId,
8480 } = msg ;
8581 const protocol = host . includes ( "localhost" ) ? "http" : "https" ;
86- console . log ( 'previewModeId' , previewModeId ) ;
8782
8883 const response = await this . service . fetch ( `${ protocol } ://${ host } ${ url } ` , {
8984 method : "HEAD" ,
@@ -95,12 +90,15 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
9590 } ) ;
9691 // Now we need to handle errors from the fetch
9792 if ( response . status === 200 && response . headers . get ( "x-nextjs-cache" ) !== "REVALIDATED" ) {
98- // 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)
93+ // 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.
94+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
9995 throw new FatalError (
10096 `The revalidation for ${ host } ${ url } cannot be done. This error should never happen.`
10197 ) ;
10298 } else if ( response . status === 404 ) {
10399 // The page is not found, we should not revalidate it
100+ // We remove the route from the failed state because it might be expected (i.e. a route that was deleted)
101+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
104102 throw new IgnorableError (
105103 `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`
106104 ) ;
@@ -113,15 +111,14 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
113111 } else if ( response . status !== 200 ) {
114112 // TODO: check if we need to handle cloudflare specific status codes/errors
115113 // An unknown error occurred, most likely from something in user code like missing auth in the middleware
114+
115+ // We probably want to retry in this case as well
116+ await this . addToFailedState ( msg ) ;
117+
116118 throw new RecoverableError ( `An unknown error occurred while revalidating ${ host } ${ url } ` ) ;
117119 }
118- // Everything went well, we can update the sync table
119- // We use unixepoch here because without IO the date doesn't change and it will make the e2e tests fail
120- this . sql . exec (
121- "INSERT OR REPLACE INTO sync (id, lastSuccess) VALUES (?, unixepoch())" ,
122- // We cannot use the deduplication id because it's not unique per route - every time a route is revalidated, the deduplication id is different.
123- `${ host } ${ url } `
124- ) ;
120+ // If everything went well, we can remove the route from the failed state
121+ this . routeInFailedState . delete ( msg . MessageDeduplicationId ) ;
125122 } catch ( e ) {
126123 // Do we want to propagate the error to the calling worker?
127124 if ( ! isOpenNextError ( e ) ) {
@@ -148,6 +145,7 @@ export class DurableObjectQueueHandler extends DurableObject<CloudflareEnv> {
148145 : expiredEvents ;
149146 for ( const event of allEventsToRetry ) {
150147 await this . executeRevalidation ( event . msg ) ;
148+ this . routeInFailedState . delete ( event . msg . MessageDeduplicationId ) ;
151149 }
152150 }
153151
0 commit comments