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

azure-storage queue async error #21039

Closed
hholst80 opened this issue Oct 4, 2021 · 7 comments
Closed

azure-storage queue async error #21039

hholst80 opened this issue Oct 4, 2021 · 7 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Storage Storage Service (Queues, Blobs, Files)

Comments

@hholst80
Copy link

hholst80 commented Oct 4, 2021

Python 3.9.7
Fedora 34 (Workstation Edition)
azure-core          1.16.0
azure-storage-blob  12.8.1
azure-storage-queue 12.1.6

I was expecting the async code below to output the exact same result as the one below when executed against an empty storage queue.

The serial code executes just fine and emits, nothing, as expected on an empty queue.
The async code throws this at me:

Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x7f7fe8b4f4f0>
transport: <_SelectorSocketTransport closing fd=6>
Traceback (most recent call last):
  File "/usr/lib64/python3.9/asyncio/selector_events.py", line 918, in write
    n = self._sock.send(data)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.9/asyncio/sslproto.py", line 684, in _process_write_backlog
    self._transport.write(chunk)
  File "/usr/lib64/python3.9/asyncio/selector_events.py", line 924, in write
    self._fatal_error(exc, 'Fatal write error on socket transport')
  File "/usr/lib64/python3.9/asyncio/selector_events.py", line 719, in _fatal_error
    self._force_close(exc)
  File "/usr/lib64/python3.9/asyncio/selector_events.py", line 731, in _force_close
    self._loop.call_soon(self._call_connection_lost, exc)
  File "/usr/lib64/python3.9/asyncio/base_events.py", line 746, in call_soon
    self._check_closed()
  File "/usr/lib64/python3.9/asyncio/base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f7fe7dda5e0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f7fe7dc8b80>, 19043.264955058)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f7fe7dda5b0>
import asyncio
import os, uuid

async def amain():
    from azure.storage.queue.aio import QueueClient
    connect_str = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
    queue_name = os.getenv("QUEUE_NAME", "events")
    queue_client = QueueClient.from_connection_string(connect_str, queue_name)
    messages = queue_client.receive_messages()
    async for msg in messages:
        print(msg.content)
        await queue_client.delete_message(msg)

def main():
    from azure.storage.queue import QueueClient
    connect_str = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
    queue_name = os.getenv("QUEUE_NAME", "events")
    queue_client = QueueClient.from_connection_string(connect_str, queue_name)
    messages = queue_client.receive_messages()
    for msg in messages:
        print(msg.content)
        queue_client.delete_message(msg)

#asyncio.run(amain())

main()
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Oct 4, 2021
@kristapratico kristapratico added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. CXP Attention Storage Storage Service (Queues, Blobs, Files) and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Oct 4, 2021
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Oct 4, 2021
@kristapratico
Copy link
Member

@hholst80 thanks for the feedback and the repro instructions, @xiafu-msft please take a look.

@HarshitaSingh-MSFT
Copy link

HarshitaSingh-MSFT commented Oct 5, 2021

@hholst80, I was able to reproduce your scenario and it looks like you might have missed out a small code piece in your asynchronous method. Please find the working code below and try running it instead:

import asyncio
import os, uuid

async def amain():

    from azure.storage.queue.aio import QueueClient
    connect_str = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
    queue_name = os.getenv("QUEUE_NAME", "events")
    queue_client = QueueClient.from_connection_string(connect_str, queue_name)

    async with queue_client:
        messages = queue_client.receive_messages()
        async for msg in messages:
            print(msg.content)
            await queue_client.delete_message(msg)

asyncio.run(amain())

Let me know if this works for you.

@hholst80
Copy link
Author

hholst80 commented Oct 5, 2021

I will try it. I might have missed it but I cannot recall seeing this construct in the documentation. I will try and find the exact link.

@HarshitaSingh-MSFT
Copy link

HarshitaSingh-MSFT commented Oct 5, 2021

@hholst80 , here is the sample code's link.

@hholst80
Copy link
Author

hholst80 commented Oct 5, 2021

@HarshitaSingh-MSFT works perfect thank you!

I based my code on this snippet here:

https://docs.microsoft.com/en-us/python/api/overview/azure/storage-queue-readme?view=azure-python

Search for Receive and process messages asynchronously

I think this can be closed, maybe a small doc update to make it clear that the queue_client needs to be wrapped as above async with ...? Or is there some implicit context here that I am not thinking of?

@HarshitaSingh-MSFT
Copy link

@hholst80, I created a PR and it is being reviewed. You can expect to see the changes soon.

@HarshitaSingh-MSFT
Copy link

@hholst80, we will now close this issue, since your query is answered and corresponding action is taken. If you have further questions, please feel free to reach out over this thread by tagging me.

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-python that referenced this issue Nov 2, 2022
Add autoIoScaling property in MySQL get/update payload (Azure#21039)

Co-authored-by: Bin Xu <bixu@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

4 participants