googlemaps / googlemaps/google-maps-services-java

GeoApiContext should clean up working threads on exit.

Abierto
#261 29 comentarios 0 reacciones 0 asignados Ver en GitHub
help wanted priority: p2 type: bug
Lenguaje dominante
Java
Estrellas
1.8k
Forks
973
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello guys, I had a problem while doing a **PlacesApi.placeAutocomplete** request
I really don't know if that is a issue caused by the API or on our implementation.

We are developing an application that uses:
* Spring Boot `1.3.6.RELEASE`
* `Undertow`
* `com.google.maps:google-maps-services:0.1.17`

```
# application.properties
server.undertow.worker-threads=1000
server.undertow.io-threads=100
```

```
# EC2 AWS
m4.xlarge
```

```Dockerfile
# Dockerfile

FROM java:8
RUN apt-get update && apt-get install -y

WORKDIR /app
VOLUME /root/.gradle

COPY gradle/ /app/gradle/
COPY gradlew /app/gradlew
COPY build.gradle /app/build.gradle
COPY src/ /app/src/

COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

CMD ["java","-jar","/app/build/libs/application-1.0.0.jar"]
```

```sh
# docker-entrypoint.sh

#!/bin/bash
set -e
./gradlew build -x test
exec "$@"
```

```java
@Service
public class GoogleMapsAPIService {
public List placeAutoComplete(String input, Double latitude, Double longitude, String language) {
GeoApiContext context = new GeoApiContext().setApiKey(GOOGLEMAPS_KEY);
LatLng location = new LatLng(latitude, longitude); // -23.52488881961586,-46.67578987777233

AutocompletePrediction[] autocompletePredictions = PlacesApi.placeAutocomplete(context, input)
.location(location)
.language("pt-BR")
.radius(1000)
.awaitIgnoreError();

return assemblyPrediction(autocompletePredictions);
}

private List assemblyPrediction(AutocompletePrediction[] autoCompletePredictions) {
List predictions = new ArrayList<>();

for (AutocompletePrediction autocompletePrediction : autoCompletePredictions) {
String placeId = autocompletePrediction.placeId;
String title = autocompletePrediction.terms[0].value;
String subTitle = Arrays.stream(autocompletePrediction.terms).skip(1).map(term -> term.value).collect(Collectors.joining(", "));

predictions.add(new Prediction(placeId, title, subTitle));
}

return predictions;
}
}
```

## **Sometimes we get this exception:**

```
2017-04-19 19:11:03,290 [XNIO-3 task-914] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/predictions] is: -1
2017-04-19 19:11:03,290 [XNIO-3 task-914] INFO com.application.services.GoogleMapsAPIService - GoogleMapsAPIService.placeAutoComplete
2017-04-19 19:11:03,290 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Passenger: [7459]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Input: [Alameda santos 2081]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Latitude: [-23.52488881961586]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Longitude: [-46.67578987777233]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Language: [pt-BR]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG com.application.services.GoogleMapsAPIService - > Radius: [1000]
2017-04-19 19:11:03,291 [XNIO-3 task-914] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: unable to create new native thread
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1305)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:979)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:281)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)

Caused by: java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:714)
at com.google.maps.internal.RateLimitExecutorService.(RateLimitExecutorService.java:63)
at com.google.maps.OkHttpRequestHandler.(OkHttpRequestHandler.java:49)
at com.google.maps.GeoApiContext.(GeoApiContext.java:88)
at com.application.services.GoogleMapsAPIService.placeAutoComplete(GoogleMapsAPIService.java:175)
at com.application.controllers.PredictionsController.predictions(PredictionsController.java:31)
```

Stacktrace:
[stacktrace.txt](https://github.com/googlemaps/google-maps-services-java/files/939432/stacktrace.txt)

Do you know what could causes that?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.