Skip to content

Non-blocking pool does not show correct FailedTasks and other counters when queue is full #100

@rogozhka

Description

@rogozhka

Hello!

Please consider to review following example:

package main

import (
	"context"
	"runtime"
	"time"

	"github.com/alitto/pond/v2"
)

func main() {
	const (
		maxWorkers = 2
		queueSize  = 10
		numJobs    = 100
	)
	wp := pond.NewPool(
		maxWorkers,
		pond.WithNonBlocking(true),
		pond.WithQueueSize(queueSize),
		pond.WithContext(context.Background()),
	)

	for i := 0; i < numJobs; i++ {
		wp.Submit(func() {
			time.Sleep(100 * time.Millisecond)
		})
	}

	println(runtime.GOMAXPROCS(0)) // 8

	go func() {
		time.Sleep(time.Second * 10)

		println(wp.SubmittedTasks())  // 12
		println(wp.CompletedTasks())  // 12
		println(wp.SuccessfulTasks()) // 12
		println(wp.FailedTasks())     // 0
	}()

	time.Sleep(time.Second * 15)
}

Playground

Based on the code, I expect that SuccessfulTasks() + FailedTasks() should be equal SubmittedTasks().
However, when the pool is full and operates in non-blocking mode, it silently drops jobs without reflecting this in any statistics.

Am I correct in understanding how these counters are supposed to work? It appears there might be an
inconsistency here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions