Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SessionContext::UploadLoop becomes a CPU spinloop #2720

Closed
mcb30 opened this issue Jun 3, 2021 · 1 comment · Fixed by #2721
Closed

SessionContext::UploadLoop becomes a CPU spinloop #2720

mcb30 opened this issue Jun 3, 2021 · 1 comment · Fixed by #2721

Comments

@mcb30
Copy link
Contributor

mcb30 commented Jun 3, 2021

The existing code in SessionContext::UploadLoop():

while (!ctx->ShouldTerminate()) {
while (jobs_processed < ctx->NumJobsSubmitted()) {
UploadJob* job = ctx->upload_jobs_->Dequeue();
if (!ctx->DoUpload(job)) {
PANIC(kLogStderr,
"SessionContext: could not submit payload. Aborting.");
}
job->result->Set(true);
delete job->pack;
delete job;
jobs_processed++;
}
if (ctx->queue_was_flushed_.IsEmpty()) {
ctx->queue_was_flushed_.Enqueue(true);
}
}

uses a simple (atomic) integer flag to indicate that the loop should terminate:
bool SessionContext::ShouldTerminate() {
return atomic_read32(&worker_terminate_);
}

At the point that all jobs have been submitted (i.e. jobs_processed is equal to ctx->NumJobsSubmitted()) but the jobs have not yet completed (because uploading is still in progress), this loop becomes equivalent to:

while (1) {
  // do nothing
}

i.e. a CPU spinloop. This behaviour can be easily observed by publishing anything via a gateway: the publisher will hit 100% CPU usage within cvmfs_swissknife sync, and attaching gdb shows that one thread is just spinning inside SessionContext::UploadLoop().

@mcb30
Copy link
Contributor Author

mcb30 commented Jun 3, 2021

A similar problem exists in S3Uploader::MainCollectResults(), which uses the same overall approach to loop termination.

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 a pull request may close this issue.

1 participant