@@ -192,6 +192,15 @@ export class WalStream {
192192 if ( slotExists ) {
193193 // This checks that the slot is still valid
194194 const r = await this . checkReplicationSlot ( ) ;
195+ if ( snapshotDone && r . needsNewSlot ) {
196+ // We keep the current snapshot, and create a new replication slot
197+ throw new MissingReplicationSlotError ( `Replication slot ${ slotName } is not valid anymore` ) ;
198+ }
199+ // We can have:
200+ // needsInitialSync: true, needsNewSlot: true -> initial sync from scratch
201+ // needsInitialSync: true, needsNewSlot: false -> resume initial sync
202+ // needsInitialSync: false, needsNewSlot: true -> handled above
203+ // needsInitialSync: false, needsNewSlot: false -> resume streaming replication
195204 return {
196205 needsInitialSync : ! snapshotDone ,
197206 needsNewSlot : r . needsNewSlot
@@ -204,7 +213,7 @@ export class WalStream {
204213 /**
205214 * If a replication slot exists, check that it is healthy.
206215 */
207- private async checkReplicationSlot ( ) : Promise < InitResult > {
216+ private async checkReplicationSlot ( ) : Promise < { needsNewSlot : boolean } > {
208217 let last_error = null ;
209218 const slotName = this . slot_name ;
210219
@@ -244,7 +253,7 @@ export class WalStream {
244253
245254 // Success
246255 logger . info ( `Slot ${ slotName } appears healthy` ) ;
247- return { needsInitialSync : false , needsNewSlot : false } ;
256+ return { needsNewSlot : false } ;
248257 } catch ( e ) {
249258 last_error = e ;
250259 logger . warn ( `${ slotName } Replication slot error` , e ) ;
@@ -274,9 +283,9 @@ export class WalStream {
274283 // Sample: publication "powersync" does not exist
275284 // Happens when publication deleted or never created.
276285 // Slot must be re-created in this case.
277- logger . info ( `${ slotName } does not exist anymore, will create new slot ` ) ;
286+ logger . info ( `${ slotName } is not valid anymore` ) ;
278287
279- return { needsInitialSync : true , needsNewSlot : true } ;
288+ return { needsNewSlot : true } ;
280289 }
281290 // Try again after a pause
282291 await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
0 commit comments