GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Datastore - Datastore object creation fails with version 1.5.1 · Issue #2440 · googleapis/google-cloud-java

Datastore - Datastore object creation fails with version 1.5.1 #2440

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore - Datastore object creation fails with version 1.5.1#2440
Copy link
Assignees
yihanzhen
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.running on app enginetype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@sai-pullabhotla
sai-pullabhotla
opened on Sep 15, 2017
Issue body actions

I'm trying to upgrade from version 1.2.3 of the Datastore API to the latest version, 1.5.1. The below sample code fails creating the Datastore object/service.

Datastore datastore = DatastoreOptions.newBuilder().build().getService();

Tests are running on my laptop with gcloud installed. Version 1.2.3 works fine by fetching the defaults (e.g. project/credentials) from Google Cloud SDK. Version 1.5.1 is producing the below exception:

Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in path at index 45: https://datastore.googleapis.com/v1/projects/<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="refresh" content="0;url=http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us"/><script type="text/javascript">url="http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}window.location.replace(url);</script></head><body></body></html>
	at com.google.datastore.v1.client.DatastoreFactory.validateUrl(DatastoreFactory.java:118)
	at com.google.datastore.v1.client.DatastoreFactory.buildProjectEndpoint(DatastoreFactory.java:104)
	at com.google.datastore.v1.client.DatastoreFactory.newRemoteRpc(DatastoreFactory.java:111)
	at com.google.datastore.v1.client.DatastoreFactory.create(DatastoreFactory.java:65)
	at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.<init>(HttpDatastoreRpc.java:71)
	at com.google.cloud.datastore.DatastoreOptions$DefaultDatastoreRpcFactory.create(DatastoreOptions.java:61)
	at com.google.cloud.datastore.DatastoreOptions$DefaultDatastoreRpcFactory.create(DatastoreOptions.java:55)
	at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:472)
	at com.google.cloud.datastore.DatastoreOptions.getDatastoreRpcV1(DatastoreOptions.java:179)
	at com.google.cloud.datastore.DatastoreImpl.<init>(DatastoreImpl.java:55)
	at com.google.cloud.datastore.DatastoreOptions$DefaultDatastoreFactory.create(DatastoreOptions.java:51)
	at com.google.cloud.datastore.DatastoreOptions$DefaultDatastoreFactory.create(DatastoreOptions.java:45)
	at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:459)
	at com.jmethods.catatumbo.DatastoreTest.main(DatastoreTest.java:29)
Caused by: java.net.URISyntaxException: Illegal character in path at index 45: https://datastore.googleapis.com/v1/projects/<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="refresh" content="0;url=http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us"/><script type="text/javascript">url="http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}window.location.replace(url);</script></head><body></body></html>
	at java.net.URI$Parser.fail(URI.java:2848)
	at java.net.URI$Parser.checkChars(URI.java:3021)
	at java.net.URI$Parser.parseHierarchical(URI.java:3105)
	at java.net.URI$Parser.parse(URI.java:3053)
	at java.net.URI.<init>(URI.java:588)
	at com.google.datastore.v1.client.DatastoreFactory.validateUrl(DatastoreFactory.java:116)
	... 13 more


I have traced it down to ServiceOptions.getAppEngineProjectId method where it tries to get the project ID from Metadata Server. Apparently, the http request executed by that method returns some string, and that string is assumed to be project ID. In my case, the default project ID is coming up as -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="refresh" content="0;url=http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us"/><script type="text/javascript">url="http://finder.cox.net/main?ParticipantID=96e687opkbv4scrood8k84drs6gw5duf&FailedURI=http%3A%2F%2Fmetadata.google.internal%2FcomputeMetadata%2Fv1%2Fproject%2Fproject-id&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}window.location.replace(url);</script></head><body></body></html>

Looks like this is an error from my Internet Service provider connecting to http://metadata.google.internal

I do not have any environment variables such as GOOGLE_* set, and solely relying on the environment set up by the gcloud tool. Why is code running on my laptop trying to find the AppEngine project ID from the metadata server? Is anyone else experiencing this?

Activity

  1. sai-pullabhotla commented on Sep 15, 2017

    @sai-pullabhotla
    sai-pullabhotla
    on Sep 15, 2017
    Author
    More actions

    Running the same code with 1.5.1 on a different network/ISP works fine. The lookup of project ID from the Metadata Server fails as expected with -

    java.net.UnknownHostException: metadata.google.internal
    

    and continues on with the subsequent searches - finds google cloud SDK's configuration file (config_default) and finds the correct project ID.

    Looks like this is an issue with some ISPs? My ISP at home is Cox and there we are getting a 200 OK response with some error text to indicate page not found for the URL http://metadata.google.internal/computeMetadata/v1/project/project-id, and the API is assuming that the error message is a project ID.

  2. sai-pullabhotla commented on Sep 15, 2017

    @sai-pullabhotla
    sai-pullabhotla
    on Sep 15, 2017
    Author
    More actions

    This is perhaps a classic example of DNS Hijacking by my ISP? Cox is listed on the page below.

    https://en.wikipedia.org/wiki/DNS_hijacking#Manipulation_by_ISPs

  3. sai-pullabhotla commented on Sep 16, 2017

    @sai-pullabhotla
    sai-pullabhotla
    on Sep 16, 2017
    Author
    More actions

    I changed my DNS at home to Google Public DNS and the issue is resolved. Not sure if there is anything that could be done in the API, like, check the returned string from the metadata server and make sure it is even a valid (length, the characters in the string, etc) project ID.

  4. neozwu commented on Sep 19, 2017

    @neozwu
    neozwu
    on Sep 19, 2017
    Contributor
    More actions

    @sai-pullabhotla Thanks for providing the detailed information. Metadata server is the last resort to fetching project id (see code here). A recommended way is to explicitly set environment variable to project id.

  5. sai-pullabhotla commented on Sep 20, 2017

    @sai-pullabhotla
    sai-pullabhotla
    on Sep 20, 2017
    Author
    More actions

    @neozwu -

    Technically speaking, fetching from gcloud settings is the last resort. In my specific case, there is a false positive from the metadata server lookup, which returns a huge HTML/JavaScript combination as the project ID. Instead of assuming it as a valid project ID, it would be nice to have some sanity check on the response to ensure it can possibly be a project ID. For example, there might be something in the response header that could be validated (e.g. Server) or to ensure the response is a valid project ID based on its length and the characters in the string.

    For example -
    Project ID must be between 6 and 30 characters.
    Project ID can have lowercase letters, digits or hyphens and must start with a lowercase letter.

    If these conditions evaluate to false, return null, so the code can continue with the next options.

  6. neozwu commented on Sep 20, 2017

    @neozwu
    neozwu
    on Sep 20, 2017
    Contributor
    More actions

    @sai-pullabhotla This indeed makes sense. I will label this as a P2 bug and will implement the validation logic.
    /cc @lesv

  7. neozwu
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    running on app engine
    on Sep 20, 2017
  8. neozwu
    self-assigned this
    on Sep 20, 2017
  9. lesv commented on Sep 20, 2017

    @lesv
    lesv
    on Sep 20, 2017
    Contributor
    More actions

    metadata.google.internal should only be hit if you are running in the cloud. The environment variables should be set that you aren't in production.

    Production is true if any of these EnvVar's are set:

    GAE_DEPLOYMENT_ID | 402856547336086879
    GAE_ENV | standard
    GAE_INSTANCE | 00c61b117c3c060e0818e8018dc0bd8dcb7397a6ca2c8ca943c2c677c170a95b93027639697422
    USER | appengine
    GAE_VERSION | gaeinfo:20170722t140621
    GAE_RUNTIME | java8

    That said, I would check the Java System Property:
    com.google.appengine.runtime.environment == Production or Development

    If Development, don't try to hit metadata.google.internal

  10. anthmgoogle
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Nov 8, 2017
  11. yihanzhen
    assigned
    yihanzhen
    and unassigned
    neozwu
    on Jan 25, 2018
  12. yihanzhen commented on Jan 29, 2018

    @yihanzhen
    yihanzhen
    on Jan 29, 2018
    Contributor
    More actions

    @pongad I believe we decided not to check if we are running in the cloud from this issue since there aren't a way to decide if we are running on GCE unless we hit the metadata server. Does that apply to this issue as well?

  13. yihanzhen commented on Feb 1, 2018

    @yihanzhen
    yihanzhen
    on Feb 1, 2018
    Contributor
    More actions

    #2822 fixes this.

  14. yihanzhen
    closed this as completedon Feb 1, 2018
  15. yihanzhen
    reopened this on Feb 1, 2018
  16. wsh commented on Feb 1, 2018

    @wsh
    wsh
    on Feb 1, 2018
    More actions

    What @lesv describes here is true for App Engine, but not for GCE/GKE. Ideally we would fix this no matter where a user is running. @hzyi-google's work in validating the response from the metadata service is a good start. If we were to check the Metadata-Flavor header we could cover GCE cases easily. and for App Engine environments we shouldn't need to contact the metadata service for this information anyway (it's in the GOOGLE_CLOUD_PROJECT environmental variable, cf. b/64313434) (I see we already do that. 😄 Yay!)

  17. yihanzhen
    closed this as completedon Feb 13, 2018
  18. theacodes
    unassigned
    yihanzhen
    on Sep 28, 2018
  19. JustinBeckwith
    assigned
    yihanzhen
    on Feb 1, 2021
  20. chingor13
    added a commit that references this issue on Feb 20, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    8d7794f
  21. chingor13
    added 3 commits that reference this issue on Mar 24, 2026

    feat: Client/StubSettings' getEndpoint() returns the resolved endpoint (

    7cf0d8f

    chore(main): release 2.39.0 (#2594)

    3ff4744

    chore(deps): update dependency com.google.cloud:libraries-bom to v26.…

    5383c46
  22. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    deps: update dependency com.google.cloud.opentelemetry:exporter-trace…

    50a3eb9

    deps: update dependency com.google.cloud.opentelemetry:exporter-trace…

    06a4e89
  23. benjaminp
    added a commit that references this issue on Jul 13, 2026

    test: temporarily disable flaky test (googleapis#2440)

    4f6eb7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @yihanzhen
    yihanzhen

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.running on app enginetype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.