-
Notifications
You must be signed in to change notification settings - Fork 224
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
Fix over acquiring of tasks in MultiThreadAgent #496
Conversation
a996234
to
d3950b4
Compare
@@ -98,12 +118,18 @@ public void run() | |||
logger.error("Uncaught exception. Task queue will detect this failure and this task will be retried later.", t); | |||
errorReporter.reportUncaughtError(t); | |||
} | |||
finally { | |||
synchronized (taskCountLock) { | |||
activeTaskCount--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using AtomicInteger
makes it a bit simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With SynchronousQueue
, calling executor.submit()
can be blocked holding taskCountLock
. As a result, a thread that tries to decrement the counter here can be potentially blocked forever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SynchronousQueue
is used with maximumPoolSize: Integer.MAX_VALUE
. So it's usually okay. But it seems a bit naive to me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point 👍 I changed the code to use AtomicInteger. Now still AgentOverAcquireIT
passes.
LGTM overall 👍 But there is a room to improve around https://github.com/treasure-data/digdag/pull/496/files#r104843071 to reduce a potential deadlock risk. Can you take a look at it? |
MultiThreadAgent.run needs to know how many tasks can start immediately. But it doesn't have to be exact number. It is OK to acquire smaller number as long as it can start the tasks immediately.
LGTM 👍 > 6926ec0 |
Fixes #487.