You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
files may be stuck in postprocessing even though the upload session is deleted #10259
We found a file that is stuck in postprocessing but the upload session has been deleted. I assume because the virus scanner emitted an event that caused the upload session to be deleted without removing the postprocessing flag.
changed the title [-]files may be stuck in postprocessing even though the uploed session is deleted[/-][+]files may be stuck in postprocessing even though the upload session is deleted[/+]on Oct 8, 2024
The ocis charts always uses "OCIS_ASYNC_UPLOADS=true", so postprocessing is always enabled. The postprocessing code in the decomposedfs is handling the events:
1. case events.PostprocessingFinished:
by default deletes the postprocessing status.
only when the ev.Outcome is events.PPOutcomeContinue and the session.Finalize() fails will we not delete the postprocessing state
The Finalize() call tries to upload the blob. Only that can fail.
2. case events.RestartPostprocessing:
does not change postprocessing state
3. case events.PostprocessingStepFinished:
does not change postprocessing state
There are other codepaths that call session.store.Cleanup(), but they are all deleting the postprocessing state:
The FinishUpload() handling might call session.store.Cleanup():
1. on a checksum error
on a calculation error or an unknown checksum we call session.store.Cleanup(ctx, session, true, false, false). The signature of that function is Cleanup(ctx context.Context, session Session, revertNodeMetadata, keepUpload, unmarkPostprocessing bool) and it calls session.Cleanup(revertNodeMetadata, !keepUpload, !keepUpload). That signature is Cleanup(revertNodeMetadata, cleanBin, cleanInfo bool). When revertNodeMetadata is true and there is a node for the session and this is the first revision of a file we completely delete the node:
// cleanup cleans up after the upload is finishedfunc (session*OcisSession) Cleanup(revertNodeMetadata, cleanBin, cleanInfobool) {
ctx:=session.Context(context.Background())
ifrevertNodeMetadata {
n, err:=session.Node(ctx)
iferr!=nil {
appctx.GetLogger(ctx).Error().Err(err).Str("sessionid", session.ID()).Msg("reading node for session failed")
} else {
ifsession.NodeExists() &&session.info.MetaData["versionsPath"] !="" {
p:=session.info.MetaData["versionsPath"]
iferr:=session.store.lu.CopyMetadata(ctx, p, n.InternalPath(), func(attributeNamestring, value []byte) (newValue []byte, copybool) {
returnvalue, strings.HasPrefix(attributeName, prefixes.ChecksumPrefix) ||attributeName==prefixes.TypeAttr||attributeName==prefixes.BlobIDAttr||attributeName==prefixes.BlobsizeAttr||attributeName==prefixes.MTimeAttr
}, true); err!=nil {
appctx.GetLogger(ctx).Info().Str("versionpath", p).Str("nodepath", n.InternalPath()).Err(err).Msg("renaming version node failed")
}
iferr:=os.RemoveAll(p); err!=nil {
appctx.GetLogger(ctx).Info().Str("versionpath", p).Str("nodepath", n.InternalPath()).Err(err).Msg("error removing version")
}
} else {
// if no other upload session is in progress (processing id != session id) or has finished (processing id == "")latestSession, err:=n.ProcessingID(ctx)
iferr!=nil {
appctx.GetLogger(ctx).Error().Err(err).Str("spaceid", n.SpaceID).Str("nodeid", n.ID).Str("uploadid", session.ID()).Msg("reading processingid for session failed")
}
iflatestSession==session.ID() {
// actually delete the nodesession.removeNode(ctx)
}
// FIXME else if the upload has become a revision, delete the revision, or if it is the last one, delete the node
}
}
}
ifcleanBin {
iferr:=os.Remove(session.binPath()); err!=nil&&!errors.Is(err, fs.ErrNotExist) {
appctx.GetLogger(ctx).Error().Str("path", session.binPath()).Err(err).Msg("removing upload failed")
}
}
ifcleanInfo {
iferr:=session.Purge(ctx); err!=nil&&!errors.Is(err, fs.ErrNotExist) {
appctx.GetLogger(ctx).Error().Err(err).Str("session", session.ID()).Msg("removing upload info failed")
}
}
}
Tried using the config POSTPROCESSING_STEPS=virusscan and ANTIVIRUS_INFECTED_FILE_HANDLING=continue, and upload a file with virus. The file gets stuck in postprocessing.
Also, the CLI command doesn't list that file. Tried with command
ocis storage-users uploads sessions
ocis storage-users uploads sessions --has-virus
For both the cases the file with virus is not listed in the response.
then, running rclone (with the 425 patch) copy of a folder with 1k 10kb files wil leave hundreds of files in the web ui stuckh in postprocessing.
The log shows:
{"level":"error","event":"PostprocessingFinished","uploadid":"07c0a8cf-accd-40f4-a61f-5348a2321101","error":"ERR_UPLOAD_NOT_FOUND: upload not found","time":"2024-10-21T13:05:51+02:00","message":"Failed to get upload"}
Also happens when using the web ui using 1000 4k files. All uploads in the web are finished but after ~500 processed uploads the upload not found errors are logged.
if these events are coming up again and again ... it might look like the postprocessing queue never ends ... hm we still need to find the reason for the reemittance of the StartPostprocessingStep events ...
the PostprocessingFinished lines show the we emit a new event, they all have a different event id
the upload processing is still going on and now i see a lot of:
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
nats: slow consumer, messages dropped on connection [37] for subscription on "main-queue"
The autoAck option only acks messages affter they have been fetched from the channel. The postrocessing service only uses one go routine to fetch events. with delays set to 1s this causes nats to consider the postprocessing service a slow consumer. Furthermore BytesReady and PostprocessingStepFinished events are handled on the main-queue, causing the processing service to become the bottleneck. In k8s deployments we start two postprocessing services which allows ocis to handle events twice as fast, but still not fast enough if virusscannig needs to handle many files.
To prevent the postprocessing from using excessive ram we will not just spawn a go routine for every event.
Instead, we will start a configurable worker group with 10 go routines.
hm the analysis is really skewed by the delay. that option has a direct impact on the processing of events, while the antivirus scanner does eg not block processing of new events while a scan is running... AFAICT @kobergj or does it?
even a workgroup of 10 will get stuck in delays ... the delay step should return immediately but start a go routine that emits a PostProcessingStepFinished event after the delay ... currently it takes a shortcut.
hm the analysis is really skewed by the delay. that option has a direct impact on the processing of events, while the antivirus scanner does eg not block processing of new events while a scan is running... AFAICT @kobergj or does it?
Correct - The antivirus service is a separate microservice. Therefore it will NOT stop postprocessing service from processing events. However there could be other limiting factors (cpu, mem) that may be depleted when antivirus runs scans
"For high throughput, set MaxAckPending to a high value. For applications with high latency due to external services, use a lower value and adjust AckWait to avoid re-deliveries."
So for postprocessing it might make sense to actually lower MaxAckPending (maybe to the size of the worker group processing the events?)
@kobergj@rhafer AFAICT the antivirus scanner has a similar bottleneck as the postprocessing service. But it is more severe:
the postrocessing service can pull events fast enough and increasing the number of replicas efficiently increases the capacity.
Increasing the number of antivirus pods does not increase the frequency of pulls from the queue: it just adds one consumer to the group, but each consumer handles events in sync. @nicholas-wilson-au is testing with 1000 10MB files. 10GB in total ... and every scan seems to take some time.
We increased the number of antivirus pods to 17, which effectively allows us to have 17 files in virus scanning at the same time. That was still not fast enough and nats tried to redeliver the 1000 messages, which only worsens the problem because we are rescanning the files 🤦
Now ... we can decrease the number of pending messages with st like:
in order to allow one pending message per consumer in the antivirus group. But since scans may take some time we may need to also tweak the ack time with eg.
Activity
[-]files may be stuck in postprocessing even though the uploed session is deleted[/-][+]files may be stuck in postprocessing even though the upload session is deleted[/+]butonic commentedon Oct 8, 2024
The ocis charts always uses "OCIS_ASYNC_UPLOADS=true", so postprocessing is always enabled. The postprocessing code in the decomposedfs is handling the events:
1. case events.PostprocessingFinished:
by default deletes the postprocessing status.
only when the
ev.Outcomeisevents.PPOutcomeContinueand thesession.Finalize()fails will we not delete the postprocessing stateThe
Finalize()call tries to upload the blob. Only that can fail.2. case events.RestartPostprocessing:
does not change postprocessing state
3. case events.PostprocessingStepFinished:
does not change postprocessing state
There are other codepaths that call
session.store.Cleanup(), but they are all deleting the postprocessing state:The FinishUpload() handling might call
session.store.Cleanup():1. on a checksum error
on a calculation error or an unknown checksum we call
session.store.Cleanup(ctx, session, true, false, false). The signature of that function isCleanup(ctx context.Context, session Session, revertNodeMetadata, keepUpload, unmarkPostprocessing bool)and it callssession.Cleanup(revertNodeMetadata, !keepUpload, !keepUpload). That signature isCleanup(revertNodeMetadata, cleanBin, cleanInfo bool). WhenrevertNodeMetadatais true and there is a node for the session and this is the first revision of a file we completely delete the node:butonic commentedon Oct 8, 2024
PrajwolAmatya commentedon Oct 18, 2024
Tried using the config
POSTPROCESSING_STEPS=virusscanandANTIVIRUS_INFECTED_FILE_HANDLING=continue, and upload a file with virus. The file gets stuck in postprocessing.Also, the CLI command doesn't list that file. Tried with command
For both the cases the file with virus is not listed in the response.
butonic commentedon Oct 21, 2024
I can reproduce files hanging in postprocessing when setting
then, running rclone (with the 425 patch) copy of a folder with 1k 10kb files wil leave hundreds of files in the web ui stuckh in postprocessing.
The log shows:
{"level":"error","event":"PostprocessingFinished","uploadid":"07c0a8cf-accd-40f4-a61f-5348a2321101","error":"ERR_UPLOAD_NOT_FOUND: upload not found","time":"2024-10-21T13:05:51+02:00","message":"Failed to get upload"}and the files are actually not present on disk.
butonic commentedon Oct 21, 2024
Also happens when using the web ui using 1000 4k files. All uploads in the web are finished but after ~500 processed uploads the
upload not found errorsare logged.8 remaining items
butonic commentedon Oct 21, 2024
hmmm five times
if these events are coming up again and again ... it might look like the postprocessing queue never ends ... hm we still need to find the reason for the reemittance of the StartPostprocessingStep events ...
the PostprocessingFinished lines show the we emit a new event, they all have a different event id
butonic commentedon Oct 21, 2024
the upload processing is still going on and now i see a lot of:
IIRC @rhafer is seeing this as well.
now ... if the wrong messages are dropped, because we are not fetching them fast enough an upload might never be processed ...
butonic commentedon Oct 21, 2024
The autoAck option only acks messages affter they have been fetched from the channel. The postrocessing service only uses one go routine to fetch events. with delays set to 1s this causes nats to consider the postprocessing service a slow consumer. Furthermore BytesReady and PostprocessingStepFinished events are handled on the main-queue, causing the processing service to become the bottleneck. In k8s deployments we start two postprocessing services which allows ocis to handle events twice as fast, but still not fast enough if virusscannig needs to handle many files.
To prevent the postprocessing from using excessive ram we will not just spawn a go routine for every event.
Instead, we will start a configurable worker group with 10 go routines.
butonic commentedon Oct 21, 2024
hm the analysis is really skewed by the delay. that option has a direct impact on the processing of events, while the antivirus scanner does eg not block processing of new events while a scan is running... AFAICT @kobergj or does it?
even a workgroup of 10 will get stuck in delays ... the delay step should return immediately but start a go routine that emits a PostProcessingStepFinished event after the delay ... currently it takes a shortcut.
kobergj commentedon Oct 22, 2024
Correct - The antivirus service is a separate microservice. Therefore it will NOT stop postprocessing service from processing events. However there could be other limiting factors (cpu, mem) that may be depleted when antivirus runs scans
butonic commentedon Oct 22, 2024
hm the activity log also does not consume events fast enough
hm ... disabling all the logpoints allowed ocis to process the events and drain the queue in a few seconds.
also ... after all events were processed all files were accessible. no file was stuck.
rhafer commentedon Oct 22, 2024
This might be interesting:
https://docs.nats.io/nats-concepts/jetstream/consumers#maxackpending
"For high throughput, set MaxAckPending to a high value. For applications with high latency due to external services, use a lower value and adjust AckWait to avoid re-deliveries."
So for postprocessing it might make sense to actually lower MaxAckPending (maybe to the size of the worker group processing the events?)
kobergj commentedon Oct 22, 2024
Good idea. Should we lower MaxAckPending then for all services?
butonic commentedon Oct 22, 2024
MaxAckPending needs to be added to go micro before we can add it in reva and then in ocis. I would save that for a new PR after #10372
nicholas-wilson-au commentedon Oct 22, 2024
butonic commentedon Oct 22, 2024
@kobergj @rhafer AFAICT the antivirus scanner has a similar bottleneck as the postprocessing service. But it is more severe:
the postrocessing service can pull events fast enough and increasing the number of replicas efficiently increases the capacity.
Increasing the number of antivirus pods does not increase the frequency of pulls from the queue: it just adds one consumer to the group, but each consumer handles events in sync. @nicholas-wilson-au is testing with 1000 10MB files. 10GB in total ... and every scan seems to take some time.
We increased the number of antivirus pods to 17, which effectively allows us to have 17 files in virus scanning at the same time. That was still not fast enough and nats tried to redeliver the 1000 messages, which only worsens the problem because we are rescanning the files 🤦
Now ... we can decrease the number of pending messages with st like:
in order to allow one pending message per consumer in the antivirus group. But since scans may take some time we may need to also tweak the ack time with eg.
now ... this can be done manually by an admin ... but we should set better defaults.
kobergj commentedon Oct 23, 2024
Closing this with follow-up: #10393