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

Apollo Client hangs in Java / Spring Boot app #1896

Closed
SledgeHammer01 opened this issue Jan 10, 2020 · 7 comments
Closed

Apollo Client hangs in Java / Spring Boot app #1896

SledgeHammer01 opened this issue Jan 10, 2020 · 7 comments
Labels
🐛 Type: Bug ⌛ Waiting for info More information is required

Comments

@SledgeHammer01
Copy link

I'm trying to use the Apollo Client Java in my Spring Boot 2.2.2.RELEASE app. Just a simple console app test app that calls my GraphQL server. The application fails to exit if I make an Apollo call. Either through legacy .enqueue / callback or RX2. I have to click the stop button TWICE to exit.

Here are some specifics:

Java: 13
Spring Boot: 2.2.2.RELEASE

dependencies {
	classpath("com.apollographql.apollo:apollo-gradle-plugin-incubating:1.2.2")
}

plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}

sourceCompatibility = '13'
targetCompatibility = '13'

apollo {
suppressRawTypesWarning = true
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:2.2.2.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-security:2.2.2.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-webflux:2.2.2.RELEASE'
implementation 'org.springframework.security:spring-security-oauth2-client:5.2.1.RELEASE'
implementation 'com.google.guava:guava:28.1-jre'
implementation 'com.apollographql.apollo:apollo-runtime:1.2.2'
implementation 'com.apollographql.apollo:apollo-rx2-support:1.2.2'
}

		this.apolloClient = ApolloClient.builder().serverUrl(url)
												  .okHttpClient(okHttpClient())
												  .build();

	private OkHttpClient okHttpClient() {
		return new OkHttpClient.Builder()//.authenticator(new BearerTokenAuthenticator(tokenProvider()))
				  						 //.addInterceptor(new BearerTokenInterceptor(tokenProvider()))
				  						 .build();
	}


No customizations on either the ApolloClient or the okHttpClient. If I make the call with the okHttpClient directly, the app exits fine.

Call is simply made as (also tried the enqueue callback method):

		GetAllCustomersQuery query = GetAllCustomersQuery.builder().build();
		ApolloCall<GetAllCustomersQuery.Data> apolloCall = this.apolloClient.query(query);
		Observable<Response<Data>> observable = Rx2Apollo.from(apolloCall);
		return observable.blockingSingle().data().getAllCustomers();

@martinbonnin
Copy link
Contributor

I've used Apollo in a command-line app that hanged because the Apollo client uses a ThreadPool and the JVM would not close until all threads terminated. I called System.exit(0) at the end of my main() to workaround that. Maybe it's a similar problem ?

@SledgeHammer01
Copy link
Author

I've used Apollo in a command-line app that hanged because the Apollo client uses a ThreadPool and the JVM would not close until all threads terminated. I called System.exit(0) at the end of my main() to workaround that. Maybe it's a similar problem ?

Yes, it appears that there are extra threads blocking. Isn't this going to be an issue in any kind of application if there is no way to cleanly shutdown the thread pool?

@SledgeHammer01
Copy link
Author

I've used Apollo in a command-line app that hanged because the Apollo client uses a ThreadPool and the JVM would not close until all threads terminated. I called System.exit(0) at the end of my main() to workaround that. Maybe it's a similar problem ?

Just for the heck of it, I tried .dispatcher(MoreExecutors.directExecutor()) on my ApolloClient builder which, from looking at the code, should disable the ThreadPool... still hangs... ugh... getting close to pulling the plug on this and just using WebClient.

@martinbonnin
Copy link
Contributor

martinbonnin commented Feb 21, 2020

The corresponding OkHttp issue: square/okhttp#5542

In some other app of mine (without apollo), a similar issue was fixed by upgrading okhttp to 4.4.0. We should update okhttp. This will bring a kotlin-stdlib dependency but I think it's okay considering #1784

@tasomaniac
Copy link
Contributor

@SledgeHammer01 can you check with Apollo 2.0? Thanks

@martinbonnin
Copy link
Contributor

Maybe duplicate of #3619?

We've upgraded OkHttp to 4.x and this should not happen anymore. Can you try with Apollo Android 3 and let us know how that goes?

@martinbonnin martinbonnin added the ⌛ Waiting for info More information is required label Dec 8, 2021
@martinbonnin
Copy link
Contributor

Closing as obsolete. Please leave a message if you want us to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug ⌛ Waiting for info More information is required
Projects
None yet
Development

No branches or pull requests

3 participants