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

Operational Error When Silk Is Used On Big SQL Queries #140

Merged
merged 3 commits into from
Sep 28, 2016

Conversation

hanleyhansen
Copy link
Member

@hanleyhansen hanleyhansen commented Sep 27, 2016

What

Keep trying the _process_response until it works. It tends to fail with big MySQL queries.

Why

MySQLdb specifically does not manage the connections and will error if you try to reuse a stale connection. One that has closed or expired. You need to explicitly check for this error case and handle it. This PR excepts the OperationalError whenever the silk middleware has to processs a relatively large query in it's _process_response.

@hanleyhansen
Copy link
Member Author

hanleyhansen commented Sep 27, 2016

@avelis we can discuss on where I put the try catch and maybe think about moving it somewhere closer to the actual cause inside of so _process_response we don't mask any other errors. Let me know your thoughts.

@hanleyhansen hanleyhansen changed the title Operational Error Through On Big SQL Queries Operational Error When Silk Is Used On Big SQL Queries Sep 28, 2016
@avelis
Copy link
Collaborator

avelis commented Sep 28, 2016

@hanleyhansen Could there ever be a scenario where you could get forever stuck in the while loop? I will likely merge but wanted to poke any holes at it before I did.

In terms of placement. I think it's fine.

@hanleyhansen
Copy link
Member Author

hanleyhansen commented Sep 28, 2016

@avelis straight from the MySQL docs

This exception is raised for errors which are related to MySQL's operations. For example: too many connections; a host name could not be resolved; bad handshake; server is shutting down, communication errors.

So the only way we can get stuck in a loop forever is if the DB server goes down. At the point the person has a different problem though. Too many connections will keep trying until there are some available connections. Communication errors, same thing. Other stuff in Django will break well before silk gets stucked in a loop forever. Otherwise just catching OperationalError and AttributeError should be safe within the while True: loop.

@avelis avelis merged commit a976e2c into jazzband:master Sep 28, 2016
@avelis
Copy link
Collaborator

avelis commented Sep 28, 2016

@hanleyhansen Thanks for the contribution and providing a solution for this scenario!

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