Hi All,
I'm running a Node.js Apollo GraphQL API using neo4j-graphql. This is connected to an AuraDB instance of Neo4j (v4).
I've recently updated @neo4j/graphql from 3.5.1 to 4.4.4 (along with updating neo4j-driver from 4.4.1 to 5.8.0 as a peer dependency), but fairly quickly ran into an issue where the connection pool was maxed out at 100 connections and new connection acquisition was timing out with the following error:
error in apollo [GraphQLError: Connection acquisition timed out in 60000 ms. Pool status: Active conn count = 100, Idle conn count = 0.]
I have not changed the schema in any way apart from to accommodate the breaking changes between v3 and v4, so I wasn't expecting to see an issue of this nature after updating.
Does anyone have similar experience after updating neo4j/graphql (or neo4j-driver)? I'm wondering if the latest version isn't closing connections properly and they're piling up.
Any help would be appreciated!
Thanks,
Simon.
Hi Simon!
That's not something we've seen reported by anyone else for now, so it might be something particular about your setup.
Could you possibly provide a sample of how you're using the ApolloServer and Neo4jGraphQL? It could be a quick fix.
Best regards,
Michael
Hi Michael,
Thanks for the quick response.
I don't think we're doing anything especially unusual, we create a neo4j-driver and schema in the normal way, then start the Apollo Server as follows:
const neoSchema = new Neo4jGraphQL({ typeDefs, driver }); // typeDefs is our raw graphQL schema, driver is the neo4j driver, initialised with a bolt URI and basic auth.
neoSchema
.getSchema()
.then((schema) => {
const server = new ApolloServer({
schema,
introspection: true,
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
context: createContext,
formatError: (err) => {
console.error("error in apollo", err);
return err;
}
});
server.listen(process.env.PORT || 3001).then(({ url }) => {
console.log(`Server ready at ${url}`);
});
})
.catch((e) => {
console.error(e);
});
The createContext function is just taking data from the HTTP request and sticking it into a jwt object for use in authentication and authorization directives
We're running the API on an AWS Elastic Beanstalk instance.
Please let me know if there's any other info I can supply.
Thanks,
Simon.
As you say, I don't see anything particularly unusual. What's the version of ApolloServer you're using?
apollo-server is at 3.6.1
Could you possibly try the latest version of ApolloServer (@apollo/server) to see if it makes any difference?
Hi Michael,
Apologies for the delay; Christmas got in the way.
I've updated to @apollo/server @ v4.9.5 but I'm still getting the same issue.
Testing on my local, where I'm the only client connecting, I can fire off queries that get quick responses (~30-50ms) again and again until I hit 100 queries. Any further queries above 100 timeout after 60s. So it seems that the 100 connections in the driver's connection pool are not being released/re-used. In this test scenario I wouldn't expect the number of connections in the pool to go above 1 as each query is completed before I make the next request.
After updating Apollo, my startup code looks like this, which is pretty much the same as the "Getting Started" documentation:
const startServer = async () => {
try {
const server = new ApolloServer({
schema: await neoSchema.getSchema()
});
const { url } = await startStandaloneServer(server, {
context: createContext,
listen: { port: parseInt(process.env.PORT) || 3001 }
});
console.log(`Server ready at ${url}`);
} catch (error) {
console.error(error);
}
};
startServer();
Any other suggestions would be welcome; I'm stumped with this one.
Thanks,
Simon.
Hey Simon, I hope you had a nice time off!
Is there any chance we could see your driver configuration (without the credentials)?
Best regards,
Michael
Sure,
I'm initialising the driver object as follows:
import { driver as neo4JDriver, auth } from "neo4j-driver";
import { neo4jConnectionUri, neo4jUsername, neo4jPassword } from "./env";
export const driver = neo4JDriver(neo4jConnectionUri, auth.basic(neo4jUsername, neo4jPassword));
Hi Michael,
I think I've resolved the issue.
I started up a new project following the "Getting Started" instructions verbatim, and there was no issue (as we would expect). I started looking for differences between the fresh project and my existing project and the first thing I spotted was that the fresh project had slightly newer dependency versions, so I update the dependencies on the existing project to match and that seems to have done the trick.
So to summarize, for anyone else who might encounter this issue, I updated the following dependencies:
- @apollo/server: 4.9.5 => 4.10.0
- graphql: 16.6.0 => 16.8.1
- neo4j-driver: 5.8.0 => 5.16.0
I'll review the change history on those packages to see if my issue was related to a known bug that's been fixed recently.
1 Like
Hi Simon,
So glad to hear you've found the solution!
Best regards,
Michael