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

getsockname fails: 'NoneType' object is not subscriptable #1057

Open
robsdedude opened this issue May 2, 2024 · 1 comment
Open

getsockname fails: 'NoneType' object is not subscriptable #1057

robsdedude opened this issue May 2, 2024 · 1 comment
Labels

Comments

@robsdedude
Copy link
Member

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

Originally posted by @ccloes in #730 (comment)

@robsdedude
Copy link
Member Author

Hi @ccloes and thanks for sharing the stack trace.

This is a very unexpected code-path, I must admit. Right after the async socket has been opened, writer.transport.get_extra_info("sockname") is being called. According to the docs and looking at the source code of asyncio, get_extra_info("sockname") will be None if there was an error receiving this information. The different transport implementations try to get the sockname right pretty much after the socket connection has been established. So there really should be a that information about the connection.

I was not able to reproduce this condition locally, so can you please provide me with additional information that should help me pin-point how this came to be:

  • Please enable debug logging and share the logs with me. You could, for instance use the driver's helper for that
    from neo4j.debug import watch
    
    watch("")
    Some of the async TCP transport implementations log errors when trying to compute the sockname for caching it in extra. Further, I'll be able to see what the failing connection was up to, before the error occurred.
  • Please install this custom version of the driver pip install -U git+https://github.com/robsdedude/neo4j-python-driver@async-sockname. It will hopefully turn this TypeError: 'NoneType' object is not subscriptable into the underlying OSError that cause the caching of sockname to fail and therefore it to be None.

@robsdedude robsdedude added the bug label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant