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

Fix over acquiring of tasks in MultiThreadAgent #496

Merged
merged 4 commits into from
Mar 13, 2017

Conversation

frsyuki
Copy link
Member

@frsyuki frsyuki commented Mar 3, 2017

Fixes #487.

@frsyuki frsyuki force-pushed the max-threads-overacquire-fix branch from a996234 to d3950b4 Compare March 3, 2017 02:53
@@ -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--;
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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...

Copy link
Member Author

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.

@komamitsu
Copy link
Contributor

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.
@frsyuki frsyuki merged commit 248f7a6 into master Mar 13, 2017
@frsyuki frsyuki deleted the max-threads-overacquire-fix branch March 13, 2017 18:48
@komamitsu
Copy link
Contributor

LGTM 👍 > 6926ec0

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 this pull request may close these issues.

2 participants