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(db) postgres connector keepalive errors on load #3423

Merged
merged 1 commit into from
May 3, 2018

Conversation

bungle
Copy link
Member

@bungle bungle commented Apr 27, 2018

Summary

Postgres strategy (new model) could result error like the below when running multiple subsequent Admin API calls rapidly (or parallel):

[error] 27206#0: *3351 lua coroutine: runtime error: /usr/local/share/lua/5.1/pgmoon/init.lua:294: bad request

@@ -158,71 +142,76 @@ function _mt:setkeepalive()
end

if not ok then
log(WARN, err)
Copy link
Member

Choose a reason for hiding this comment

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

Even if pre-existing prior to this PR, such logging message really should have some context prepended to them for users to understand their meaning.


if connection then
return connection:query(sql)
local function query(sql, self)
Copy link
Member

Choose a reason for hiding this comment

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

Not following the self as a first argument convention - maybe we should?

Copy link
Member

Choose a reason for hiding this comment

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

I also notice we made this function a local, but the only place it is being called is in _mt:query() - it seems like unnecessary abstraction?

if connection then
return connection:query(sql)
local function query(sql, self)
if self.connection and self.connection.sock then
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't the fix be more concise if it simply added checks for self.connection.sock in the places you just added it? I'm not quite sure making setkeepalive() and connect() local functions really helps? It seems like it just makes the logic more difficult to follow: we sometimes call setkeepalive(), and some other times call self:setkeepalive() - the latter just unsetting self.connection, but that seems unnecessary since the former will already unset self.connection.sock, and we now check for this value in query()?)

@bungle bungle force-pushed the fix/pg-connector-keepalive branch 3 times, most recently from 76db0be to d991cb9 Compare April 27, 2018 20:29
@bungle bungle force-pushed the fix/pg-connector-keepalive branch from d991cb9 to 4d4e049 Compare April 27, 2018 20:30
@thibaultcha
Copy link
Member

thibaultcha commented May 2, 2018

I still struggle to see the difference before and after the patch, a lot of it seems to be re-factoring. What is the part that fixes it exactly, and what was the root cause for the bug? The PR description is very vague on details.

@bungle
Copy link
Member Author

bungle commented May 2, 2018

The biggest change is that when you don't have self.connection the self:query doesn't set one either, it just creates connection, uses it and sets keepalive, but it doesn't touch this self.connection in any way.

@bungle
Copy link
Member Author

bungle commented May 2, 2018

But I agree, if user ever calls :connect I think we might have a problem, with both cassandra and pg. That's why I would prefer that something in our system makes connection available per request and closes/keepalives it after. Something other that this strategy instance field, which may be shared between single worker on several requests.

@thibaultcha
Copy link
Member

Gotcha. The :connect() method was intended for users (likely, said users are us) who know they will need to make several queries at once. It is fine in the CLI or init contexts, but not at runtime indeed, since the DAO is shared between all requests, one of those queries could yield and another request could use the DAO, which by then has this connection object as an attribute...

Let's merge this for now, and consider what to do with :connect() later!

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.

None yet

2 participants