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

firestore client has OpenSSL error when trying to connect to Firestore emulator in docker #260

Closed
sutera opened this issue Nov 16, 2020 · 3 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.

Comments

@sutera
Copy link

sutera commented Nov 16, 2020

Environment details

OS type and version:
    Debian GNU/Linux 10 Cloud-SDK Docker image
Python version: 3.8.6
pip version: 20.2.4
google-cloud-firestore version: 2.0.1

Steps to reproduce

after `docker-compose up` running the below script fails on the set/write to the DB.

Code

from google.cloud import firestore
from unittest import mock
from google.auth.credentials import Credentials

dev_creds = mock.MagicMock(spec=Credentials)
db = firestore.Client(project="dev",credentials=dev_creds)
data = {u"user_id": 123, u"user_stuff": "slfk"}

doc_ref = db.collection(u'testcollection').document()
doc_ref.set(data)

Stack trace

python stacktrace when using firebase emulators:start --only firestore

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 923, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 826, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1605569542.888990900","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4165,"referenced_errors":[{"created":"@1605569534.418268900","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":397,"grpc_status":14}]}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/document.py", line 128, in set
    write_results = batch.commit(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/batch.py", line 57, in commit
    commit_response = self._client._firestore_api.commit(
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 750, in commit
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/usr/local/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 199, in retry_target
    six.raise_from(
  File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x7f14c30878b0>, database: "projects/dev/databases/(default)"
writes {
  update {
    name: "projects/dev/databases/(default)/documents/testcollection/dcoybcbsJAObuPhTHoRw"
    fields {
      key: "user_id"
      value {
        integer_value: 138
      }
   }
    fields {
      key: "user_stuff"
      value {
        string_value:: "slfk"
      }
    }
  }
}
, metadata=[('google-cloud-resource-prefix', 'projects/dev/databases/(default)'), ('authorization', 'Bearer owner'), ('x-goog-request-params', 'database=projects/dev/databases/%28default%29'), ('x-goog-api-client', 'gl-python/3.8.6 grpc/1.33.2 gax/1.23.0 gapic/2.0.0')]), last exception: 503 failed to connect to all addresses

python stacktrace when using gcloud beta emulators firestore start --host-port="0.0.0.0:8080"

E1117 13:57:48.365762952     430 ssl_transport_security.cc:1439] Handshake failed with fatal error SSL_ERROR_SSL: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 923, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 826, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1605621588.162605021","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4165,"referenced_errors":[{"created":"@1605621583.057953160","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":397,"grpc_status":14}]}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/document.py", line 128, in set
    write_results = batch.commit(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/batch.py", line 57, in commit
    commit_response = self._client._firestore_api.commit(
  File "/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/services/firestore/client.py", line 750, in commit
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/usr/local/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 199, in retry_target
    six.raise_from(
  File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x7fa64120e1f0>, database: "projects/dev/databases/(default)"
writes {
  update {
    name: "projects/dev/databases/(default)/documents/testcollection/MSEoKQrRSMUeUUrFVlri"
    fields {
      key: "user_id"
      value {
        integer_value: 138
      }
   }
    fields {
      key: "user_stuff"
      value {
        string_value:: "slfk"
      }
    }
  }
}
, metadata=[('google-cloud-resource-prefix', 'projects/dev/databases/(default)'), ('authorization', 'Bearer owner'), ('x-goog-request-params', 'database=projects/dev/databases/%28default%29'), ('x-goog-api-client', 'gl-python/3.8.6 grpc/1.33.2 gax/1.23.0 gapic/2.0.0')]), last exception: 503 failed to connect to all addresses

emulator logs when using gcloud

Executing: /usr/lib/google-cloud-sdk/platform/cloud-firestore-emulator/cloud_firestore_emulator start --host=0.0.0.0 --port=8080
[firestore] API endpoint: http://0.0.0.0:8080
[firestore] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
[firestore]
[firestore]    export FIRESTORE_EMULATOR_HOST=0.0.0.0:8080
[firestore]
[firestore] Dev App Server is now running.
[firestore]
[firestore] Nov 17, 2020 1:57:48 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[firestore] INFO: Detected non-HTTP/2 connection.
[firestore] Nov 17, 2020 1:57:48 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
[firestore] INFO: Unknown request URI: /bad-request

compose file

version: '3.7'
services:
  firestore:
    build: ./firestore-dev
    volumes:
      - ./firestore-data:/opt/data
      - ./firestore-dev:/firestore
    environment:
      - FIRESTORE_PROJECT_ID=dev
      - GOOGLE_APPLICATION_CREDENTIALS=/firestore/ddc-creds.json
    command: firebase emulators:start --only firestore
    # command: gcloud beta emulators firestore start --host-port="0.0.0.0:8080"
    networks: 
      - my-net
  web:
    build: ./
    volumes: 
      - ./:/my-volume
    environment:
      - FIRESTORE_PROJECT_ID=dev
      - FIRESTORE_EMULATOR_HOST=firestore:8080
    command: bash -c "while true; do sleep 1; done" 
    depends_on: 
      - firestore
    networks: 
      - my-net
networks:
  my-net:
    driver: bridge
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Nov 16, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Nov 17, 2020
@HemangChothani HemangChothani added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Nov 19, 2020
@HemangChothani
Copy link
Contributor

HemangChothani commented Nov 19, 2020

@sutera I think this issue is related to grpc/grpc#9538, but i am not able to reproduce it.

Could you please try with the fresh environment:

1. pip install virtualenv
2. virtualenv my_env
3. source my_env/bin/activate
4. pip install google-cloud-firestore 

Start the emulator:

 gcloud beta emulators firestore start --host-port=localhost:8080
  • export FIRESTORE_EMULATOR_HOST=localhost:8080

UPDATE: Please update the google-cloud-sdk

Run the code:

from google.cloud import firestore
from unittest import mock
from google.auth.credentials import Credentials

dev_creds = mock.MagicMock(spec=Credentials)
db = firestore.Client(project="dev",credentials=dev_creds)
data = {u"user_id": 123, u"user_stuff": "slfk"}

doc_ref = db.collection(u'testcollection').document()
doc_ref.set(data)

@sutera
Copy link
Author

sutera commented Nov 19, 2020

I deleted the images created by docker-compose and rebuilt. The emulator started from gcloud and firebase tools both work.

@SulanthaM
Copy link

This seems to have appeared again: #359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants