google-api-java-client icon indicating copy to clipboard operation
google-api-java-client copied to clipboard

DefaultCredentialProvider should detect GAE Standard

Open janhicken opened this issue 6 years ago • 0 comments

This is the same issue as #1083, which has been fixed with #1109. However, the PR's changes but got reverted shortly after with #1123.

Now, I'm running into issues using the Cloud Endpoints framework on App Engine Standard with Java 8. I've registered a ControlFilter to publish API metrics to the Service Management API. This process uses the DefaultCredentialProvider to obtain credentials to authenticate against the Service Management API. The flushing of these metrics will get executed in a different thread, so the error shown below (see stacktrace) is thrown. I would expect that no App Identity credential will be used in GAE Standard Java 8, instead the Metadata Server should be queried for a token (Compute Engine credential).

Environment details

  • OS: App Engine Standard
  • Java version: 8
  • google-api-java-client version: 1.25.0

Steps to reproduce

  1. Add endpoints-management-control library
  2. Add a configured ControlFilter to the EndpointsServlet
  3. Wait for the App Identity credential to be requested from memcache

Stacktrace

com.google.api.control.Client scheduleFlushes: scheduler com.google.api.control.Client@7d1da3d0 failed and exited (Client.java:304)
com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call memcache.Get in a thread that is neither the original request thread nor a thread created by ThreadManager at 
com.google.apphosting.api.ApiProxy$CallNotFoundException.foreignThread(ApiProxy.java:844) at 
com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:183) at 
com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:180) at 
com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:93) at 
com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:28) at 
com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:51) at 
com.google.appengine.api.appidentity.AppIdentityServiceImpl.getAccessToken(AppIdentityServiceImpl.java:302) at 
com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.intercept(AppIdentityCredential.java:100) at 
com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper.intercept(AppIdentityCredential.java:245) at 
com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859) at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at 
com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at 
com.google.api.control.Client.flushAndScheduleReports(Client.java:397) at 
com.google.api.control.Client.access$200(Client.java:61) at 
com.google.api.control.Client$4.run(Client.java:416) at 
com.google.api.control.Client$Scheduler.run(Client.java:765) at 
com.google.api.control.Client$Scheduler.run(Client.java:775) at 
com.google.api.control.Client.scheduleFlushes(Client.java:297) at 
com.google.api.control.Client.access$000(Client.java:61) at 
com.google.api.control.Client$2.run(Client.java:137) at 
java.lang.Thread.run(Thread.java:745)

janhicken avatar Jan 08 '19 12:01 janhicken