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
Emulator support broken since 2.1.0 at least on Windows #359
Comments
Because Poetry does not yet allow ignoring version dependency numbers I need Firedantic to not depend on a broken version of google-cloud-firestore: python-poetry/poetry#697 For most people this will still install the latest version, but I can pin the version to 2.0.2 with this change until Google fixes the big with the emulator support googleapis/python-firestore#359
* Added supported google-cloud-firestore versions Because Poetry does not yet allow ignoring version dependency numbers I need Firedantic to not depend on a broken version of google-cloud-firestore: python-poetry/poetry#697 For most people this will still install the latest version, but I can pin the version to 2.0.2 with this change until Google fixes the big with the emulator support googleapis/python-firestore#359 * Update the content-hash in poetry.lock Avoids `Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.` when running poetry install. Co-authored-by: Joakim Nordling <joakim.nordling@digitalliving.fi>
Thanks for the detailed issue and repro, @lietu |
Thanks for the report, also, just to simplify the repro, This won't resolve your error, though the following code should result in a repro:
|
Maybe that |
I have failed to reproduce this on macOS, and combined with @dmahugh's reproduction on Windows; OS would seem to be a relevant factor. Continuing to investigate. |
I can verify that this problem does not exist for: |
Assigning dmahugh as I think they are planning to look into this. |
I spent a bit of time testing this further and it seems Linux is not affected, quite likely Windows-only. |
This is a bit easier to test on for Windows because the async client for some reason crashes immediately instead of waiting for a timeout import asyncio
from os import environ
from unittest.mock import Mock
import google.auth.credentials
from google.cloud import firestore
def get_db() -> firestore.AsyncClient:
if environ.get("FIRESTORE_EMULATOR_HOST"):
print("Connecting to emulator")
return firestore.AsyncClient(
project="firestore-test",
credentials=Mock(spec=google.auth.credentials.Credentials),
)
else:
print("Connecting to live environment")
return firestore.AsyncClient()
async def main():
# Add a new document
print("Creating document")
doc_ref = db.collection(u'users').document(u'alovelace')
await doc_ref.set({
u'first': u'Ada',
u'last': u'Lovelace',
u'born': 1815
})
# Then query for documents
print("Reading documents")
users_ref = db.collection(u'users')
async for doc in users_ref.stream():
print(u'{} => {}'.format(doc.id, doc.to_dict()))
if __name__ == "__main__":
db = get_db()
asyncio.run(main())
|
So it seems emulator (or anything?) can't be used with
The same async example from above crashes with this on 2.0.2
Version 2.0.0 complains about |
Debugged this with @dmahugh for a while and we eventually hit a dead end when the code path turned entirely into compiled C. This is where our adventures took us:
{
"created":"@1626734356.729000000",
"description":"Failed to pick subchannel",
"file":"src/core/ext/filters/client_channel/client_channel.cc",
"file_line":3009,
"referenced_errors": [
{
"created":"@1626734354.049000000",
"description":"failed to connect to all addresses",
"file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc",
"file_line":398,
"grpc_status":14
}
]
} So it seems that something in this compiled C code is not correctly building or reading the server's URL when environment variables have been set to indicate a URL of the form |
Sounds like you traced it back to gRPC - I might be naive here, but it sounds to me like it's not gRPC's job to parse EDIT: Oh hm, I think I misread what you wrote. I also checked with the debugger that in the Python side transport the host was correctly set and the |
Those are good points, @lietu. I had wondered if the emulator's networking layer was simply broken on Windows, but I expect that would have surfaced by now in one version of this ticket for each language Firebase supports, so I don't imagine the issue is there. |
If this is really an issue with connecting because of secure vs insecure channels in gRPC - I would hope that once this is tracked down that someone goes and creates an issue with gRPC about improving this message to include some information about that, since to me "failed to connect to all addresses" sounds like an issue with parsing the address, whereas something like "failed to connect to all addresses (failed to open secure connection)" or similar would've told me basically instantly that the issue is somewhere with trying to open secure connections to localhost, which is very often the case. |
How very strange, it seems something recently changed that fixes this, it seemed to me like it was something in gRPC. Using https://github.com/lietu/google-cloud-firestore-emulator-bug-test poetry install
poetry run test.bat Now both async and sync clients work on Windows as well. Just prior to pushing that repo I had the same issues with that, but then I ran
And if I run Seems like the problem is solved, though it would be nice to know the root cause. |
The changelog doesn't seem to hint at the potential solution The C side included this which is the closest thing I can see that could be related grpc/grpc#26331 |
Can confirm that a more complex project started working by doing |
This seem to not have fixed my issue. Here is my env.
|
Strange, also I couldn't reproduce any issue on Mac or Linux when tested, so your issue might be different from mine. Have you checked that
? |
More detail:
And connecting to Firestore like:
I am also connecting to secret manager with a correct credential file, but I don't think that could be an issue. App Start:
|
I created a testing project for ease of test. Would it be possible to try to see where the issue here is. |
@SulanthaM can you confirm if It installs the emulator on the same container as it runs the tests on. If so, this could be e.g. the secure/insecure channel selection not working when not using |
Fix merged in #402. Will be present in the next release (already present if installed from master) |
That seems to have been unrelated, as this was fixed without using |
Using master fixed the issue for me but, now I see this error in mocking credentials.
This is my code.
|
Mjea, this is now broken again but in a very different way. poetry add git+https://github.com/googleapis/python-firestore google-cloud-firestore Breaks both async and sync client, with that above issue. The workaround is:
It would also be nice if the earlier claim was true about not needing to override the credentials for emulator, but it's not: #359 (comment) poetry add google-cloud-firestore==2.1.3 # or 2.1.0, 2.1.1, or 2.1.2 Fixes the problem reported in this issue with |
This issue seems resolved to me, it was somehow resolved in It would be very nice still to guarantee that in the future we get better and more descriptive errors than "failed to connect to all addresses". |
@lietu Thanks, Your workaround to set id_token in credentials fixed the issue and I will use it until that's officially fixed. |
I assume the maintainers of this project know better where to raise the open issue of getting reasonable error messages instead of "failed to connect to all addresses", such as
|
It wasn't unrelated and I validated your issue and resolved it via this. It is possible grpc fixed the fact that local channel credentials + secure channel didn't work on windows though, which is what my change routed around ;) It may no longer be necessary, but it is definitely related. :) |
@SulanthaM the issue you likely ran into is the emulator wasn't providing the header for token, which would leave off an authorization header, and then be rejected as an invalid request. My fix to move to insecure also included this change. |
To validate: @lietu is indicating the following combintation works on windows: google-cloud-firestore==2.1.3 We should validate this. it sounds like even with this, id_token needs to be set in credentials which is a change we could make internally with emulator credentials. @dmahugh could you validate this on your windows machine? (while we did resolve this reopening just in case we really can revert) |
https://github.com/lietu/google-cloud-firestore-emulator-bug-test with
works
fails
while working:
while failing:
not sure how you're testing but this is how I create my async client https://github.com/lietu/google-cloud-firestore-emulator-bug-test/blob/991829f3897aa59da1e290f0f275a6f3218b7c6a/asyncmain.py#L9-L17 |
Updated version of grpcio to fix the emulator support googleapis/python-firestore#359 (comment) With grpcio>=1.39.0 Windows can again connect to emulator easily, and both async and sync variants work.
Environment details
google-cloud-firestore
version: 2.1.0 - 2.1.1 at least are affectedSteps to reproduce
pip install google-cloud-firestore
in e.g. a virtualenvgcloud beta emulators firestore start --host-port=127.0.0.1:8686
FIRESTORE_EMULATOR_HOST=127.0.0.1:8686
environment variablefailed to connect to all addresses
on first database accessCrashes near instantly if you use the
async
client but synchronous client gets it after some lengthy timeout.If you run this exact same code but
pip install google-cloud-firestore==1.9.0
, it works perfectly.==2.0.0
crashes becauseGOOGLE_APPLICATION_CREDENTIALS
is not set?2.0.1
works,2.0.2
works.I tried the myriad of other
FIREBASE_FIRESTORE_EMULATOR_ADDRESS
etc. and none of them seemed to resolve anything, and the documentation nor the code does not seem to support that this should be necessary. I also tried running the emulator viafirebase emulators:start --only firestore
but that seemed to be just a downgrade without solving any problems - it didn't allow me to set the port without some configuration file.The emulator logs show no connection attempts or other issues from the broken client versions.
Code example
Your own example code modified just to work with an emulator in general:
Stack trace
From
==2.1.1
The text was updated successfully, but these errors were encountered: