fsjobqueue: do not delete empty channels

Previously, we deleted empty channels when a job was dequeued. This is
completely wrong because there still might be some clients waiting for
a job. This commit removes the cleanup and adds a regression test.

Note that this has the potential to leak memory if we ever use a lot of
job types. Currently, we have just handful of them, so this is fine.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2021-11-10 18:17:58 +01:00 committed by Sanne Raymaekers
parent a880c9c019
commit 5f4db72777
2 changed files with 39 additions and 9 deletions

View file

@ -21,6 +21,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/jsondb"
)
@ -202,15 +203,6 @@ func (q *fsJobQueue) Dequeue(ctx context.Context, jobTypes []string) (uuid.UUID,
id, err := selectUUIDChannel(ctx, chans)
q.mu.Lock()
// Delete empty channels
for _, jt := range jobTypes {
c, exists := q.pending[jt]
if exists && len(c) == 0 {
close(c)
delete(q.pending, jt)
}
}
if err != nil {
if errors.As(err, &context.Canceled) || errors.As(err, &context.DeadlineExceeded) {
return uuid.Nil, uuid.Nil, nil, "", nil, jobqueue.ErrDequeueTimeout