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

Non-threadsafe Entitymanager instance #288

Open
256cats opened this issue Nov 9, 2020 · 0 comments
Open

Non-threadsafe Entitymanager instance #288

256cats opened this issue Nov 9, 2020 · 0 comments

Comments

@256cats
Copy link

256cats commented Nov 9, 2020

Hi, we are using this library in a Spring Boot application and discovered that DefaultGraphQLJpaQueryConfiguration produces non-threadsafe EntityManager instance and we experienced possible non-threadsafe access to the session exception under load.

Specifically, in https://github.com/introproventures/graphql-jpa-query/blob/master/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfiguration.java#L62 :

@Bean
@ConditionalOnMissingBean
@ConditionalOnSingleCandidate(EntityManagerFactory.class)
public GraphQLSchemaBuilder graphQLJpaSchemaBuilder(final EntityManagerFactory entityManagerFactory,
                                                            ObjectProvider<RestrictedKeysProvider> restrictedKeysProvider) {
            GraphQLJpaSchemaBuilder bean = new GraphQLJpaSchemaBuilder(entityManagerFactory.createEntityManager());
            
            restrictedKeysProvider.ifAvailable(bean::restrictedKeysProvider);
            
            return bean;
}

Here entityManagerFactory.createEntityManager() returns Hibernate's SessionImpl which is not threadsafe.

Replacing it with Spring-provided EntityManager bean solved the issue:

@PersistenceContext
private EntityManager entityManager;
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

No branches or pull requests

1 participant