Skip to content

Threads created and not destroyed with each client #239

Closed

Description

@dgmp88

Each time you search on a client, new threads are created that are not destroyed. e.g. if you need to use many clients and run

def test():
    auth_string = """****"""
    client = google_ads.client.GoogleAdsClient.load_from_string(auth_string)
    service = client.get_service("GoogleAdsService")
    res = service.search(
        "****", "select campaign.resource_name from campaign limit 1"
    )
    res = list(res)


for i in range(10000):
    test()

Then run watch -n1 "ps -eLf | wc -l" in another terminal, you can see the number of threads creeping up. After a while you'll reach your machines thread limit then have lots of system wide problems.

If you comment out the last line turning the results generator into a list, the problem disappears, so I think the thread creation is occurring there?

As far as I can tell there isn't a .close() function on the client or service I'm missing?

Activity

  1. wihl commented on Mar 7, 2020

    @wihl
    Contributor

    What version of the library are you using? We just released v5 yesterday.

  2. dgmp88 commented on Mar 8, 2020

    @dgmp88
    Author

    It was on the previous version, but I just tested on 5 and still see the thread count creeping up. I'm running on Ubuntu 18.04.

  3. BenRKarl commented on Mar 9, 2020

    @BenRKarl
    Contributor

    @dgmp88 If you put a print(len(threading.enumerate())) call after the call to test you can see the thread count increase by one after each call. I'd expect the threads to get closed after the generator is finished with the request. I'm going to file an issue with the gRPC team to see if they can help identify the issue.

  4. self-assigned this
    on Mar 9, 2020
  5. added
    bugSomething isn't working
    P1Breaking issue affecting some users or workflows
    on Mar 9, 2020
  6. BenRKarl commented on Mar 9, 2020

    @BenRKarl
    Contributor

    @dgmp88 can you clarify which version of the grpcio module you have installed when you see this? I don't see the issue when I use the newest 1.27.2

  7. dgmp88 commented on Mar 9, 2020

    @dgmp88
    Author

    Thanks for the quick replies!

    threading - good point, that's far simpler!

    I just checked, I'm also using 1.27.2 and still seeing this.

  8. dgmp88 commented on Mar 9, 2020

    @dgmp88
    Author

    I also just updated everything i could think of (had an older version of grpc-cpp), but still seeing the issue

  9. BenRKarl commented on Mar 9, 2020

    @BenRKarl
    Contributor

    @dgmp88 which version of Python are you using? And are you using a virtualenv?

  10. BenRKarl commented on Mar 9, 2020

    @BenRKarl
    Contributor

    @dgmp88 Can you confirm whether you see this issue if you downgrade google-auth to version 1.7.1? I can consistently repro with 1.7.2 and later, but not with 1.7.1.

  11. dgmp88 commented on Mar 9, 2020

    @dgmp88
    Author

    I'm using python 3.7 with anaconda (pip for installing the google ads api) and was on google-auth 1.11.2 .

    Yep, it's google-auth! Good find. Threads don't increase on 1.7.1, and do on 1.7.2 for me as well.

    Thanks so much for the speedy diagnosis! I'll downgrade for the time being.

  12. BenRKarl commented on Mar 9, 2020

    @BenRKarl
    Contributor

    @dgmp88 I opened this issue with the Auth team, you can track progress there. Until there's a change on their end the best way forward is to pin google-auth to 1.7.1

  13. pinned this issue on Mar 9, 2020
  14. BenRKarl commented on Mar 30, 2020

    @BenRKarl
    Contributor

    Version 1.12.0 of google-auth was released which fixes this issue, when installing google-ads-python it will get downloaded automatically so I'm going to close this issue. If anyone has this problem again make sure to update your dependencies and verify you have a >= 1.12.0 version of google-auth installed.

  15. unpinned this issue on Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Breaking issue affecting some users or workflowsbugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions