The manager's Close function is prone to race condition
CermakM opened this issue · comments
Describe the bug
When calling the RunTask
with a long running task def after Close
, the task gets cancelled.
To Reproduce
Use the samples/slog
example and add another manager.Close()
call after the existing Close
call and immediately after add manager.RunTask(ctx, def)
. The task is executed and killed after a moment.
Expected behavior
One possible solution is to forbid execution of tasks after the manager has been closed (this is a similar philosophy as for other Go Close
methods, for example closing a request's body (io.ReadCloser
) also does not allow to read from the body anymore (closed socket). I would imagine a lot of people will expect such behavior from a Close
method.
If you don't want this kind of behavior, I would consider renaming the method to Stop
instead and resolve the race condition.