-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
KeyError: 'endpoint_resolver' #801
Comments
Is this function being called in multiple threads? The only way I see that happening is if |
Hi James, |
@vinczente Yes, each thread should have its own session. |
I'm getting this in one case out of tens of thousands, but consistently in this case. I'm already creating a resource per thread... My code inside the thread is:
This happens inside a lambda function (it invokes other lambda functions). The exact error is:
I tried replacing it with
But this causes:
Any other options to try? |
So it seems you can only create lambda clients using the default session? I'm not allowed to get it from a custom session, and |
@cpury Looking back at my code, I cannot remember why I didn't go with the session solution (perf? maybe) but what I have now is (simplified):
then the code is calling execute_async |
@vinczente thanks for your code! So you're using a shared client for all threads? My code is similar, but more complex. I'm using a ThreadPool, though. And I create the client in each thread. I should have emphasized more clearly: My code works in 99.9999% of all cases! The lambda function (that calls other lambda functions) has been run on tens of thousands of files as inputs, and never failed. There is exactly one file where this error consistently appears. I assume there are weird edge cases where this can happen, and you might run into it yourself at some point :( So it would be great if at least there was a way to create a lambda client that's not using the default session, as that would likely fix this. |
Wow, super weird! Inspired by your code, I changed mine to use a global lambda client object that's shared among all threads. AKA, do exactly the opposite of what's recommended here in this ticket. And that fixes it! So for anyone running into the same issue: Just use a global lambda object. And if anyone of the boto3 team wants to explain how this makes sense, please do, I'm curious :) |
@cpury , I observed the same issue too. It gave the exception when I use separate client per thread and only works if I use one global client. |
@cpury: I ran into the same issue as well. I wasn't comfortable creating a global client due to this documentation, so I tried until I get a client, e.g.
This seems to work. |
@junghoon-picwell that looks scary, but great that it works! I've changed jobs so can't confirm if that fixes our case. |
Yes, it does make me uncomfortable. I introduced retry limits now, but I don't think it is still good. Any thoughts? |
Is this issue fixed after #73? I hit this exception, and thought threading might be the issue, but it might have been a false alarm. It turned out the proxy server I was using went down. When I switched to a working proxy server, the I was using threads, and I haven't yet had a chance to dig into whether pointing to a bad proxy server while not using threading triggers this. |
I observe similar behavior on v1.9.16, but the error is Making client global also "fixes" the error. #1592 seems to be relevant. |
Ideal fix would be
(note that its not using sesion.resource() which is only applicable for small number of resources) All the clients created using boto3.client()/boto3.resource() share default global session and thus aren't thread safe. Lines 85 to 100 in c939956
|
The problem with the "global fix" for me is that with the shared lambda client I get about 50% more invocations than I have workers/threads. Can't explain why that's happening, but a client per session fixes that. When it works :) And it often doesn't. |
I'm running into this now. I have a Flask application sitting behind Apache. When multiple clients are accessing a resource in the Flask app, that request triggers a boto3.client('s3').list_objects call, where this error comes up. |
Try using concurrent.futures |
I'm still encountering this issue on The
fix seems to work, though. |
What if I need to pass the key and secret in each call because there are different accounts? How do I do this? I can't put the Is there any solution that works to my problem?
I need to declare the id/key each time so can't do it globally as explained before |
I'm using uWSGI |
As suggested here boto/boto3#801 (comment), The occasional error we get `KeyError: 'endpoint_resolver'` should be fixed if we replace `boto3.client()` with `s3_session.client()` .
boto3 client has known issues for multithreading. boto/boto3#801 One solution is to use session instead.
My solution was creating a session for each thread and reusing that session in a particular thread: # boto.py
from threading import local
thread_local_storage = local()
def get_s3_resource():
if not hasattr(thread_local_storage, 'boto_session'):
thread_local_storage.boto_session = boto3.Session()
return thread_local_storage.boto_session.resource('s3')
# consumer.py
s3 = get_s3_resource()
# rest of the code |
boto3 client has known issues for multithreading. boto/boto3#801 One solution is to use session instead.
Hi,
I sometimes get that error trying to call a lambda function
boto3==1.3.1
payload is in this format:
error seems to be coming from get_component in botocore/session.py
Can you help ?
The text was updated successfully, but these errors were encountered: