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

Kill workers that are stuck in long running queires #21

Closed
wants to merge 8 commits into from

Conversation

Licenser
Copy link

This PR take a brutal approach at assassinating workers that happen to time out due to long running requests! This might not be the perfect solution, I'm more then open to better alternatives.

This is fixes the issue described in #20

Please be aware that as a side effect it includes hex related changes.

gen_server:call(W, {squery, Sql},
Timeout)
catch
exit:E ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more specific like exit:timeout?

catch
exit:E ->
exit(W, kill),
exit(E)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, probably it would be better to keep original stacktrace by using erlang:raise(exit, E, get_stacktrace())

gen_server:call(W, {equery, Sql, Params},
Timeout)
catch
exit:E ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here. Maybe use generic wrapper?

gen_server:call(W, {transaction, Fun},
Timeout)
catch
exit:E ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again

@Licenser
Copy link
Author

very good points!

try
Fun(Worker)
catch
Type:Error ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, are you sure you want to catch all errors, not exit = Type:{timeout, _} = Reason?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly yes, given that the current code can return incapacitated workers to the pool which can cause serious issues I think killing a worker too many might be better then killing a worker too few.

But all the calls wrapped are nothing more then a gen_server:call so the only other exception possibly being thrown I can think of are all exits anyway.

@Licenser Licenser closed this Aug 24, 2024
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