Repository navigation
Description
Describe the bug
Uploads can permanently fall out of the postprocessing pipeline. The upload session stays processing=true (status e.g. started postprocessing step: virusscan), ClamAV is idle, and the upload never finishes on its own. opencloud storage-users uploads sessions --processing=true --resume finishes them immediately.
Root cause: in several places, postprocessing and antivirus ack a JetStream message, or hold the follow-up work only in memory, before the next state is durably stored or published. A transient NATS error (e.g. the default 5s request timeout) or a process restart at that moment loses the only event that drives the upload. Nothing detects the orphan afterwards: there is no step deadline and no reconciler.
The clearest case: when postprocessing cannot read the upload's record from its KV store, it returns an error but still acks the incoming PostprocessingStepFinished (the antivirus result). The scan result is discarded, and the upload stays in virusscan forever. Store write errors and publish errors are already handled correctly (ackEvent = false → redelivery); the read path is not.
Steps to reproduce
- Run OpenCloud v9.2.0 with
POSTPROCESSING_STEPS=virusscanand the ClamAV scanner. The default postprocessing store isnats-js-kvon the same NATS as the events. - Upload a large burst of small files (e.g. a source tree with thousands of
.javafiles) so that NATS requests start timing out. - Observe:
opencloud storage-users uploads sessions --processing=truekeeps listing uploads that never finish;- ClamAV is idle (no active scans) while those uploads are shown as
started postprocessing step: virusscan; - nothing changes over time; pod restarts do not finish them.
- Run
opencloud storage-users uploads sessions --processing=true --resume. All listed uploads are scanned and finish, i.e. the pipeline itself is healthy; only the driving event was lost.
Deterministic reproduction of the main code path (unit test level): give postprocessing a store whose Read returns a non-ErrNotFound error, deliver a PostprocessingStepFinished, and observe that the event is acked and nothing is published.
Expected behavior
Transient NATS/KV errors and restarts delay uploads but never lose them:
- a message is acked only after the next state is stored and the successor event is published;
- otherwise it is not acked (or
Naked), so JetStream redelivers it; - uploads stuck in one step longer than a timeout are picked up again automatically.
Actual behavior
- Uploads stay
processing=trueindefinitely and are only recovered by a manual--resume. - ClamAV is idle because no event for these uploads exists anymore (the status text is set by storage-users, not by antivirus, see below).
- The losses cluster during upload bursts, because the same NATS carries all events (published synchronously) and the postprocessing KV, and every event is delivered to every consumer group.
Setup
- OpenCloud v9.2.0 (tag
8b4139136232a5feac39c24be9a7a03d46c67bfc); the same code is onmainas of 2026-11-20. - reva v3.0.1, go-micro natsjs v1.2.2, nats.go v1.55.0, nats-server v2.15.0, store
opencloud-eu/go-micro-plugins/v4/store/[email protected]. - Deployment:
Details
POSTPROCESSING_STEPS=virusscan
POSTPROCESSING_STORE=nats-js-kv
ANTIVIRUS_SCANNER_TYPE=clamav
ANTIVIRUS_WORKERS=10
Additional context
All line numbers below are from v9.2.0; on main they are identical or shifted by up to 3 lines.
1. postprocessing acks the event when the store read fails (main bug)
services/postprocessing/pkg/service/service.go
183 ackEvent := true
184 defer func() {
185 if ackEvent {
186 if err := e.Ack(); err != nil { ... }
...
208 case events.PostprocessingStepFinished:
...
219 pp, err = pps.getPP(pps.store, ev.UploadID)
220 if err != nil {
221 pps.log.Error().Str("uploadID", ev.UploadID).Err(err).Msg("cannot get upload")
222 return fmt.Errorf("%w: cannot get upload", ErrEvent) // ackEvent still true -> acked, result lost
223 }The same pattern exists at :258-262 (StartPostprocessingStep / delay) and :271-275 (UploadReady).
By contrast, the code already does this correctly for writes and publishes:
303 if err := storePP(pps.store, pp); err != nil {
304 ackEvent = false
...
311 if err := pps.publishWithRetry(ctx, &e, next); err != nil {
312 // The successor event never made it onto the bus. Don't ack the source event so
313 // jetstream redelivers it and the upload can continue instead of being stuck in
314 // the store forever.
315 ackEvent = falseWhy a read can fail transiently:
getPP(:371-380) maps onlystore.ErrNotFoundtoErrNotFoundand returns every other store error as is (log:reading from store: upload store read error).- The store plugin's
getRecord(nats-js-kv/nats.go:457-462) mapsnats.ErrKeyNotFoundtostore.ErrNotFoundand wraps every otherbucket.Geterror asFailed to get object from bucket. bucket.Getis a JetStream request ([email protected]/kv.go:642-662,GetLastMsg) with the default request waitdefaultRequestWait = 5 * time.Second(js.go:303); reva'spkg/store/store.go:143-147sets no other JetStream options.- By default the store and the events use the same NATS endpoint (
services/postprocessing/pkg/config/defaults/defaultconfig.go:31, 43).
2. postprocessing retries and delays live only in memory
service.go:226-246: on outcome: retry the incoming event is acked, and the retry is a goroutine:
230 go func() {
231 time.Sleep(backoff)
...
242 err := events.Publish(ctx, pps.pub, retryEvent)
243 if err != nil {
244 pps.log.Error()...Msg("cannot publish RestartPostprocessing event") // only logged
245 }
246 }()NextStep(postprocessing.go:59-64) returns aPostprocessingRetryevent, which is published immediately, but nothing consumesPostprocessingRetryin OpenCloud or reva v3.0.1. The goroutine above is therefore the only thing that ever re-sends the step.- The retry is lost if the process restarts during the backoff, or if that single publish fails (no retry, not acked-later, only logged).
- Backoff:
RetryBackoffDuration5s × 2^(failures−1),MaxRetries14 (defaultconfig.go:37-38,postprocessing.go:95-100), so a single wait reaches 5s × 2^13 ≈ 11.4 h. - The
delaystep has the same pattern:Delay(postprocessing.go:79-85) sleeps in a goroutine, and the publish error is only logged (service.go:263-267).
3. antivirus acks before scanning, and exits on a publish error
-
services/antivirus/pkg/service/service.go:135:events.Consume(natsStream, "antivirus", events.StartPostprocessingStep{})(reva typed consumer). There is noAck()anywhere inservices/antivirus. -
The typed consumer goes through go-micro natsjs,
js.QueueSubscribe(topic, group, handleMsg, ...)([email protected]/nats.go:242-244), withoutnats.ManualAck(). -
nats.go then auto-acks after the callback returns (
[email protected]/js.go:1941-1945):// Auto acknowledge unless manual ack is set or policy is set to AckNonePolicy if cb != nil && !o.mack && o.cfg.AckPolicy != AckNonePolicy { ocb := cb cb = func(m *Msg) { ocb(m); m.Ack() } }
The callback returns as soon as the event has been handed to reva's channel (
natsjs nats.go:193-198), i.e. before the download and scan. -
If publishing the result fails, antivirus calls
log.Fatal(service.go:253-255, also:156,:160inRun). The process exits, and every event already handed over (up toANTIVIRUS_WORKERS+ 1) is lost. In an all-in-one deployment where antivirus runs in the same process, this also restarts postprocessing and loses all in-memory retries from (2).
(Postprocessing itself was changed in #3347 to retry publishing instead of exiting; antivirus was not.)
4. Why this clusters during upload bursts
- Every event goes to one subject: reva
events.Publish→s.Publish(MainQueueName, ...)(reva pkg/events/events.go:179), and natsjs publishes onevent.Topic(natsjs nats.go:135-145). - Publishing is synchronous: reva sets
natsjs.SynchronousPublish(true)(reva pkg/events/stream/nats.go:67), so every publish waits for the PubAck. - No consumer sets a subject filter (
FilterSubjectappears nowhere in the natsjs plugin or inraw), and each service uses its own durable group. Every event is therefore delivered to every group: in v9.2.0 that isuserlog,storage-users,sse-<uuid>,sharing,postprocessing-pull,policies,notifications,graph,evhistory,clientlog,auth-guest,audit,antivirus,activitylog,search-pull, plus reva-internalstorage-usersupload,dcfs-revisionsandjsoncs3sharemanager(depending on enabled services). Most groups discard the event, but NATS still delivers and tracks each copy. - The postprocessing KV is served by the same NATS.
A burst of small uploads therefore produces many timeouts at once, and paths (1)–(3) create many orphaned uploads at the same time.
5. No self-healing: orphans are never picked up again
- The upload state exists twice: the storage-users session (
processing=true+ status text) and the postprocessing KV record (Status.CurrentStep). No component checks that an event for the upload still exists, and there is no step deadline or reconciler. - The visible status text is misleading:
started postprocessing step: virusscanis set by storage-users' own consumer when it sees theStartPostprocessingStep(revapkg/upload/postprocessing.go:101-112), independently of whether antivirus received it or its result arrived. - Recovery is manual:
uploads sessions --resume(services/storage-users/pkg/command/uploads.go:213) →ResumePostprocessing→resumePP(service.go:440-461) re-publishespp.CurrentStep(), or publishesRestartPostprocessingif the record is gone.
Suggested fixes
-
Do not ack on transient store read errors (all three
getPPcall sites):pp, err = pps.getPP(pps.store, ev.UploadID) if err != nil { if !errors.Is(err, ErrNotFound) { ackEvent = false // transient store error: let JetStream redeliver } pps.log.Error().Str("uploadID", ev.UploadID).Err(err).Msg("cannot get upload") return fmt.Errorf("%w: cannot get upload", ErrEvent) }
Keep acking on
ErrNotFound, so events without an upload (e.g. postprocessing logs "cannot get upload" for every non-empty file the posix driver assimilates #3606) are not redelivered forever. -
Make retries and delays durable: keep the retry/delay deadline in the postprocessing store (or use JetStream
NakWithDelayon the source event) instead oftime.Sleepgoroutines, and do not drop a failed retry publish. -
antivirus: ack after the result is published: migrate it to
raw.Streamlike postprocessing (raw.EventhasAck/Nak/InProgress), ack after publishingPostprocessingStepFinished,Nakon retryable errors, and replacelog.Fatalon a publish error with a retry (as fix(postprocessing): retry publishing events instead of killing the server #3347 did for postprocessing).AckWaitmust exceedANTIVIRUS_CLAMAV_SCAN_TIMEOUT(default 5m). -
Add a reconciler: periodically re-publish the current step for uploads that have been in one step longer than its timeout (an automated
postprocessing resume). -
(Load, optional) Use subject-filtered consumers so each service only receives the event types it handles.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][Bug] antivirus never acks main-queue events: JetStream stalls at max_ack_pending (1000), clamd goes idle and uploads stay in postprocessing[/-][+][Bug] postprocessing acks PostprocessingStepFinished when the upload store read fails, so the antivirus result is lost and uploads stay in processing forever[/+][-][Bug] postprocessing acks PostprocessingStepFinished when the upload store read fails, so the antivirus result is lost and uploads stay in processing forever[/-][+][Bug] postprocessing/antivirus ack events before the work is durable: transient NATS errors orphan uploads in "processing" until a manual resume[/+]RyoKusnadi commentedon Nov 20, 2026
Hi @suse-coder @aduffeck, can I do it? Only fix 1 from the issue, the rest stays open.
How I plan to do it:
services/postprocessing/pkg/service/service.go,processEventacks by default (ackEvent := true). The store-write and publish failures already setackEvent = false, but the threegetPPerror branches (PostprocessingStepFinished,StartPostprocessingStep,UploadReady) don't, so a transient store error still acks.ackEvent = falsewhen the error isn'tErrNotFound, so the event gets redelivered.ErrNotFound, so events for uploads the service doesn't know aren't redelivered forever.service_test.gowith a store whoseReadfails with a non-not-found error: the event isn't acked and nothing is published, for all three event types.ErrNotFoundstill acks, and a normal read still acks.Durable retries/delays, the antivirus ack and a reconciler (items 2-5) I'd leave for separate PRs if you want them.