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 4 commits into from Apr 2, 2019


None yet
2 participants
Copy link

commented Apr 1, 2019


  • 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


This comment has been minimized.

Copy link
Member Author

commented Apr 2, 2019

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.


This comment has been minimized.

Copy link
Member Author

commented Apr 2, 2019

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

1 check passed

continuous-integration/jenkins/pr-merge This commit looks good

@dasrecht dasrecht deleted the 920-mariadb-conn-per-request branch Apr 10, 2019

@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
You can’t perform that action at this time.