Skip to content

fix(incremental): reject revalidateTag when the tag state could not be written - #23

Merged
leejpsd merged 1 commit into
mainfrom
fix/revalidate-tag-unconfirmed-write
Nov 13, 2026
Merged

leejpsd merged 1 commit into
mainfrom
fix/revalidate-tag-unconfirmed-write

Conversation

@leejpsd

@leejpsd leejpsd commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Closes #13.

Problem

With no Redis connection (failed initialization, or the reconnect cooldown) getOrConnect() returns null. The singular handler's revalidateTag returned from its callback, fell through to the success path and emitted tag.invalidate.* with backend: "redis". Nothing had been written, other instances kept serving the old entry, and the caller could not tell.

A failed or timed-out write already rejected. Only the no-connection case was silent, which also contradicted docs/api.md.

Change

Throw when there is no client. The existing catch decides what propagates, so the no-connection case now behaves exactly like a failed write: an invalidation with a deadline (no durations, or durations with an expire) rejects, and no success metric is emitted. The local stamp is applied before the remote write, so the calling process is invalidated either way. Memory-only modes (fallback: "always", build phase, instance-local: tags) are untouched.

Verification

Unit: 196 passed. The 6 new cases fail on current main.

End to end on Next.js 16.4.6, real Redis stopped mid-run:

Call site 1.0.2 This PR
Server Action, updateTag() 200, success metric 500, no metric
Server Action, revalidateTag(tag, 'max') 200, success metric 200, error logged, no metric
Route Handler, revalidateTag(tag, 'max') 200, success metric 200, error logged, no metric

Next awaits the invalidation only for updateTag() in a Server Action. For revalidateTag(tag, 'max') it runs the handler after the response, so the rejection is logged by Next rather than returned to the client. Pages keep being served from the memory fallback during the outage, and invalidation works again once Redis is back.

Not in this PR

The issue also proposes waiting for auto-connecting ioredis clients and new cluster options. Those are separate changes.

…e written

With no Redis connection (failed initialization, or the reconnect
cooldown) getOrConnect() returns null. revalidateTag returned from its
callback, fell through to the success path and emitted a
tag.invalidate metric with backend "redis", so the caller could not
tell an unwritten invalidation from a confirmed one while other
instances kept serving the old entry.

Throw in that case. The existing catch already decides what propagates:
an invalidation with a deadline rejects, exactly as it does when the
write fails or times out. The local stamp is applied before the remote
write, so the calling process is invalidated either way. Memory-only
modes are untouched.

Closes #13
@leejpsd
leejpsd merged commit e3a1d9a into main Nov 13, 2026
5 checks passed
@leejpsd
leejpsd deleted the fix/revalidate-tag-unconfirmed-write branch November 13, 2026 07:02
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Singular revalidateTag resolves without confirmed Redis writes after cluster initialization failure

1 participant