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

Unclosed socket after calling the buckets_api #66

Closed
t-schanz opened this issue Mar 3, 2020 · 5 comments · Fixed by #67
Closed

Unclosed socket after calling the buckets_api #66

t-schanz opened this issue Mar 3, 2020 · 5 comments · Fixed by #67
Labels
bug Something isn't working
Milestone

Comments

@t-schanz
Copy link

t-schanz commented Mar 3, 2020

When running Unittest on the following minimal example of code, I get a Warning that not all resources are closed.

import unittest
import os

from influxdb_client import InfluxDBClient
import tracemalloc

tracemalloc.start()


class InfluxTest(unittest.TestCase):

    def setUp(self) -> None:
        self.client = InfluxDBClient(url=os.environ.get("INFLUX_URL"),
                                     token=os.environ.get("INFLUX_TOKEN"))
        self.bucket_api = self.client.buckets_api()

    def tearDown(self) -> None:
        self.client.__del__()
        del self.bucket_api

    def test_connection(self):
        self.bucket_api.find_buckets().to_dict()

When I use other APIs like the query_api, I don't get that warning. Does it have something to do with the bucket API not having a __del__() method?

This is the warning I get (I replaced my ip with xxxx):

ResourceWarning: unclosed <socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('x.x.x.x', 50040), raddr=('x.x.x.x', 9999)>
  del self.bucket_api
Object allocated at (most recent call last):
  File "/Users/myuser/opt/anaconda3/envs/myenv/lib/python3.7/site-packages/urllib3/util/connection.py", lineno 65
    sock = socket.socket(af, socktype, proto)`
@bednar
Copy link
Contributor

bednar commented Mar 3, 2020

Hi @tmachnitzki,

I tried your code by: pytest github_test.py and everything works correctly.

My environment is: platform darwin -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1

Please, could you provide more info how to simulate it?

Regards

@t-schanz
Copy link
Author

t-schanz commented Mar 3, 2020

I use Python 3.7.6 on macOS Catalina. Unfortunately I am not able to find out the unittest version number, as it is neither listed in conda or pip, nor does the package has a __version__ string.

Using pytest I am not getting the warning either, only using unittest with
python -m unittest github_test.py.

@bednar
Copy link
Contributor

bednar commented Mar 3, 2020

The problem is caused by unclosed pool_manager:

self.pool_manager = urllib3.PoolManager(

The pool_manager should be closed at:

@bednar bednar added this to the 1.5.0 milestone Mar 3, 2020
@bednar bednar added the bug Something isn't working label Mar 3, 2020
@bednar bednar closed this as completed in #67 Mar 3, 2020
@bednar
Copy link
Contributor

bednar commented Mar 3, 2020

Hi @tmachnitzki,

The issue is fixed in 1.5.0 milestone.

If you would like to use a dev version then install client via:

pip install git+https://github.com/influxdata/influxdb-client-python.git@master

Regards

@t-schanz
Copy link
Author

t-schanz commented Mar 3, 2020

I can confirm that it is solved, thanks for the support 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants