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

For broken queries EventListenerMangager.queryCompleted() is called too early #20225

Open
dominikzalewski opened this issue Dec 27, 2023 · 2 comments

Comments

@dominikzalewski
Copy link
Member

Summary

The majority of the queries are processed in such a way that we first call QueryTracker.addQuery() and only later EventListenerManager.queryCompleted(). For badly broken failed queries, for instance ones that have invalid SQL syntax, the order of the calls is inverted. As a result, EventListeners that want to access query details, fail in this edge case.

Current Workaround

EventListener is coded using a separate thread that waits (usually 100 milliseconds) so that the call to QueryTracker.addQuery() has a chance of completing in the main thread before EventListener.queryCompleted() is finished.

This mechanism does not always give good results, especially on overloaded systems where 100 milliseconds is not enough wait time.

Code details

DispatchManager.createQueryInternal():

  • failedDispatchQueryFactory.createFailedDispatchQuery() calls EventListenerManager.queryCreated()
  • queryCreated() calls QueryTracker.addQuery()
@hashhar
Copy link
Member

hashhar commented Dec 27, 2023

cc: @dain @sopel39

An example would be an event listener that tries to collect query JSONs for all queries - currently it can only do so reliably for non-failed queries. For failed queries the query JSON isn't available timely and if the listener waits then it's available.

What can be done to make sure that the events sent to listeners don't depend on when the event listener executes?
There is a comment about changing the order might impact event listeners registered via SystemAccessControl. Would it make sense to decouple engine provided functionality (audit logging SAC) vs user provided code (e.g. EventListener)?

What alternative options are there?

@dominikzalewski
Copy link
Member Author

See this PR: #20231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants