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

[EventGrid] async EventGridPublisherClient does not close session #16126

Closed
swathipil opened this issue Jan 13, 2021 · 0 comments · Fixed by #16321
Closed

[EventGrid] async EventGridPublisherClient does not close session #16126

swathipil opened this issue Jan 13, 2021 · 0 comments · Fixed by #16321
Assignees
Labels
blocking-release Blocks release Client This issue points to a problem in the data-plane of the library. Event Grid Messaging Messaging crew

Comments

@swathipil
Copy link
Member

  • Package Name: azure-eventgrid
  • Package Version: 2.0.0b5
  • Operating System: Windows 10
  • Python Version: 3.7

Describe the bug
Async EventGridPublisherClient does not close the client using aexit. Need to fix async samples to remove warning.

To Reproduce
Steps to reproduce the behavior:

  1. Run the following sample, adding the right credentials to environment variables as needed:
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: cs1_publish_custom_events_to_a_topic_async.py
DESCRIPTION:
    These samples demonstrate sending an EventGrid Event asynchronously.
USAGE:
    python cs1_publish_custom_events_to_a_topic_async.py
    Set the environment variables with your own values before running the sample:
    1) EG_ACCESS_KEY - The access key of your eventgrid account.
    2) EG_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format
    "<YOUR-TOPIC-NAME>.<REGION-NAME>.eventgrid.azure.net".
"""
import os
import asyncio

from azure.eventgrid.aio import EventGridPublisherClient
from azure.eventgrid import EventGridEvent, CloudEvent
from azure.core.credentials import AzureKeyCredential

async def publish():
	topic_key = os.environ["EG_ACCESS_KEY"]
	topic_hostname = os.environ["EG_TOPIC_HOSTNAME"]

	credential = AzureKeyCredential(topic_key)
	client = EventGridPublisherClient(topic_hostname, credential)

	await client.send([
		EventGridEvent(
			event_type="Contoso.Items.ItemReceived",
			data={
				"itemSku": "Contoso Item SKU #1"
			},
			subject="Door1",
			data_version="2.0"
		)
	])

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(publish())

Expected behavior
Samples should run without warning.

Warning

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000002414047DEF0>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x00000241404BD388>, 119561.203)]']connector: <aiohttp.connector.TCPConnector object at 0x000002414047DEB8>
@swathipil swathipil added Event Grid Client This issue points to a problem in the data-plane of the library. labels Jan 13, 2021
@swathipil swathipil added this to the [2021] February milestone Jan 13, 2021
@yunhaoling yunhaoling added the blocking-release Blocks release label Jan 13, 2021
@lmazuel lmazuel added the Messaging Messaging crew label Apr 12, 2021
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this issue Sep 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocking-release Blocks release Client This issue points to a problem in the data-plane of the library. Event Grid Messaging Messaging crew
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants