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

'NoneType' object is not subscriptable #730

Closed
nikhildosapati64sqs opened this issue May 31, 2022 · 7 comments
Closed

'NoneType' object is not subscriptable #730

nikhildosapati64sqs opened this issue May 31, 2022 · 7 comments

Comments

@nikhildosapati64sqs
Copy link

nikhildosapati64sqs commented May 31, 2022

I got an error that the 'NoneType' object is not subscriptable. I created an AsyncGraphDatabase.driver. Got response from neo4j db with the initial request. Later after one hr approx I got the error as below.

Neo4j Version: 4 Professional
Neo4j Mode: Aura DB
Driver version: Python driver 5.0.0a1
Operating System: Windows 11

Steps to reproduce

  1. Run a query with the AsyncGraphDatabase.driver.
  2. Receives response
  3. keep idle for 1hr
  4. Run the same query

Expected behavior

The second query shall run successfully

Actual behavior

File "C:\Users\aksha\Downloads\api\.\utils\AsyncNeo4jClient.py", line 53, in get_data
    data = await db.read_transaction(work)
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\work\session.py", line 407, in read_transaction
    return await self._run_transaction(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\work\session.py", line 327, in _run_transaction
    await self._open_transaction(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\work\session.py", line 257, in _open_transaction
    await self._connect(access_mode=access_mode)
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\work\session.py", line 109, in _connect
    await super()._connect(access_mode)
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\work\workspace.py", line 80, in _connect
    self._connection = await self._pool.acquire(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 657, in acquire
    await self.ensure_routing_table_is_fresh(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 602, in ensure_routing_table_is_fresh
    await self.update_routing_table(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 552, in update_routing_table
    if await self._update_routing_table_from(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 495, in _update_routing_table_from
    new_routing_table = await self.fetch_routing_table(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 436, in fetch_routing_table
    new_routing_info = await self.fetch_routing_info(
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 406, in fetch_routing_info
    cx = await self._acquire(address, timeout)
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_pool.py", line 116, in _acquire
    await connection.close()
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_bolt4.py", line 330, in close
    log.debug("[#%04X]  C: GOODBYE", self.local_port)
  File "c:\users\aksha\appdata\local\programs\python\python39\lib\site-packages\neo4j\_async\io\_bolt4.py", line 100, in local_port
    return self.socket.getsockname()[1]
TypeError: 'NoneType' object is not subscriptable
@robsdedude
Copy link
Member

robsdedude commented Jun 2, 2022

Thanks for the report.

Unfortunately, I was not able to reproduce it (at least not without waiting 1h, which is a little too long for debugging). But I'm pretty sure that #724 (for 5.0) and #726 (for 4.4) will fix this.

I am not quite sure what makes socket.getsockname() return None after a connection was established. I'm guessing it might be an OS specific thing, since you reported to run on Windows.

@ccloes
Copy link

ccloes commented Apr 30, 2024

We have experienced this issue as well. We are using the neo4j driver version 5.19.0.

Can we have you reinvestigate this?

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/nodestream/pipeline/pipeline.py", line 196, in try_work_body
    await self.work_body()
  File "/usr/local/lib/python3.11/site-packages/nodestream/pipeline/pipeline.py", line 171, in work_body
    async for index, record in enumerate_async(results):
  File "/usr/local/lib/python3.11/site-packages/nodestream/pipeline/pipeline.py", line 20, in enumerate_async
    async for item in iterable:
  File "/usr/local/lib/python3.11/site-packages/nodestream/pipeline/writers.py", line 22, in handle_async_record_stream
    await self.flush()
  File "/usr/local/lib/python3.11/site-packages/nodestream/databases/writer.py", line 54, in flush
    await self.ingest_strategy.flush()
  File "/usr/local/lib/python3.11/site-packages/nodestream/databases/debounced_ingest_strategy.py", line 69, in flush
    await self.flush_relationship_updates()
  File "/usr/local/lib/python3.11/site-packages/nodestream/databases/query_executor_with_statistics.py", line 34, in upsert_relationships_in_bulk_of_same_operation
    await self.inner.upsert_relationships_in_bulk_of_same_operation(
  File "/usr/local/lib/python3.11/site-packages/nodestream_plugin_neo4j/query_executor.py", line 68, in upsert_relationships_in_bulk_of_same_operation
    await self.database_connection.execute(
  File "/usr/local/lib/python3.11/site-packages/nodestream_plugin_neo4j/neo4j_database.py", line 40, in execute
    result = await self.driver.execute_query(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/driver.py", line 921, in execute_query
    return await session._run_transaction(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/work/session.py", line 543, in _run_transaction
    await self._open_transaction(
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/work/session.py", line 423, in _open_transaction
    await self._connect(access_mode=access_mode)
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/work/session.py", line 130, in _connect
    await super()._connect(
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/work/workspace.py", line 178, in _connect
    self._connection = await self._pool.acquire(**acquire_kwargs_)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 913, in acquire
    await self.ensure_routing_table_is_fresh(
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 855, in ensure_routing_table_is_fresh
    await self.update_routing_table(
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 777, in update_routing_table
    if await self._update_routing_table_from(
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 723, in _update_routing_table_from
    new_routing_table = await self.fetch_routing_table(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 660, in fetch_routing_table
    new_routing_info = await self.fetch_routing_info(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 628, in fetch_routing_info
    cx = await self._acquire(address, auth, deadline, None)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 316, in _acquire
    return await connection_creator()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 166, in connection_creator
    connection = await self.opener(
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_pool.py", line 560, in opener
    return await AsyncBolt.open(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_bolt.py", line 475, in open
    connection = bolt_cls(
                 ^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_bolt5.py", line 472, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_bolt5.py", line 79, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/neo4j/_async/io/_bolt.py", line 141, in __init__
    self.local_port = self.socket.getsockname()[1]
                      ~~~~~~~~~~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

@thelonelyvulpes
Copy link
Contributor

@ccloes Could you look at using https://neo4j.com/docs/api/python-driver/current/api.html#liveness-check-timeout-ref it should prevent this exception being thrown in the application layer, and the driver should continue functioning.

Could you also provide any further context on how this error occurred? thanks.

@ccloes
Copy link

ccloes commented May 1, 2024

We are using that already. This is how we are trying to utilize it in the context of our NLB.

    # According to this:
    # https://medium.com/expedia-group-tech/lesson-learned-from-a-nlb-connection-timeout-2c672e59e197
    # NLB has a 350 second timeout. We set the timeout to 300 seconds to be safe.
    max_connection_lifetime: 300
    # As of driver version 5.15, the `liveness_check_timeout` option is available.
    # https://neo4j.com/docs/api/python-driver/current/api.html#liveness-check-timeout-ref
    # We'll set that to half the `max_connection_lifetime` in order to ensure that
    # the driver is able to detect a dead connection before the NLB does.
    liveness_check_timeout: 150

Do you have any experience with NLB timeouts and how best to mitigate these connection issues?

@thelonelyvulpes
Copy link
Contributor

thelonelyvulpes commented May 1, 2024

While I do not, but it is a good place to start looking(in that we do not see many reporting this issue and load balancers are very capable of creating annoying network behaviours). For a little more context, are you attempting to connect to a neo4j instance through an NLB or is your application behind a NLB and it is reaching out to a neo4j instance i.e. AuraDB?

@robsdedude
Copy link
Member

Thanks for your input @ccloes. I've moved your comment into a separate issue to track it separately as it's very similar but not quite the same situation as the original post.

@robsdedude
Copy link
Member

@ccloes can you please take a look at the linked issue and provide the additional information I've requested so that I can continue investigating the error? This would be a tremendous help for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants