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

Use a new MariaDB connection object for every api request #1012

Merged
merged 4 commits into from
Apr 2, 2019

Conversation

rocketeerbkw
Copy link
Member

Checklist

  • Affected Issues have been mentioned in the Closing issues section
  • Documentation has been written/updated.
  • Changelog entry has been written

Moved the sqlClient constructor inside of the Apollo server and express middlewares so that a new connection will be generated for every request. Putting it in the Apollo Server and passing it to resolvers via context means the connection will be shared when multiple resolvers need to be called to fulfill one request.

90% of the code changes are just adding sqlClient to the resolvers and auto-formatting changes. The magic happens in apolloServer.js and authMiddleware.js

Changelog Entry

Improvement - Each API request will generate a new MariaDB connection (#920)

Closing issues

closes #920

@rocketeerbkw
Copy link
Member Author

Seeing a lot of error messages now about too many connections:

api_1 | error: message=Too many connections, stack=Error: Too many connections, code=1040

It looks like connections must explicitly be closed, combined with a new connection for every request makes sense that it runs out. Just looking at the docs for apollo server I can't see any way to close the connection after a request has been "finished." Will have to dig into code or ask SO or somewhere.

@rocketeerbkw
Copy link
Member Author

Found an undocumented plugin system in apollo server that can listen to request pipeline events. I no longer get connection errors, and tests are green.

@Schnitzel Schnitzel merged commit 344fd54 into master Apr 2, 2019
@dasrecht dasrecht deleted the 920-mariadb-conn-per-request branch April 10, 2019 11:38
@Schnitzel Schnitzel added this to the v0.23.0 milestone May 15, 2019
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.

refactor api mariasql usage: open new connection for each graphql request
2 participants