Conversation
|
Another good example for troubleshooting and drill to the end:) |
|
We can use a simple demo to show VCR.py is not thread-safe: import vcr
import requests
import logging
import threading
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s\t%(name)s\t%(thread)d\t%(threadName)s\t%(message)s")
def thread_function():
inner_response = requests.get('https://httpbin.org/get')
print(inner_response.status_code)
with vcr.use_cassette('recordings.yaml'):
new_thread = threading.Thread(target=thread_function)
new_thread.start()
response = requests.get('https://httpbin.org/get')
print(response.status_code)
new_thread.join()Even there is only one entry in the recording, the script will succeed, with one request going to the recording, one request going to the internet. This is because VCR.py has a Detail: kevin1024/vcrpy#295, kevin1024/vcrpy#212 |
|
The change caused 3 test failures because |
|
@DaeunYim for aware |
| address_space=AddressSpace( | ||
| address_prefixes=[ | ||
| vnet_address_pref]))) | ||
| vnet_address_pref]))).result() |
There was a problem hiding this comment.
Another solution proposed by @zhoxing-ms is to supply polling=False to nw_client.virtual_networks.begin_create_or_update so that LROPoller is created with NoPolling:
if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, path_format_arguments=path_format_arguments, **kwargs)
elif polling is False: polling_method = NoPolling()This stops SDK from polling the result. The Virtual Network creation will then be superseded/canceled by Subnet creation.
Pros
- This is faster as it doesn't care about the result of Virtual Network creation.
Cons
- This leaves the result of Virtual Network creation unchecked. If the Virtual Network creation actually fails, the error will be reported at
making troubleshooting difficult. - This depends on the service's ability to allow one operation to be superseded by another. In many other services like Storage, this is not always the case - we can't create a container before Storage Account creation finished.
DaeunYim
left a comment
There was a problem hiding this comment.
Looks good to me. Please merge and let me continue working based on this change. Thanks a lot, Jiashuo and team!
Symptom
RDBMS tests frequently fail (like in #17127):
https://dev.azure.com/azure-sdk/public/_build/results?buildId=759999&view=logs&j=74095127-2a27-5370-37ed-15a4193f243f&t=5cf5f89a-09fb-583c-72e4-4e4427c89fb1&l=167520
Cause
When
virtual_networks.begin_create_or_updateis not waited,requestswill be called by theLROPollerthread andMainThreadat the same time. As VCR.py is not designed to be thread-safe (kevin1024/vcrpy#213 (comment)), some request will bypass VCR and reach to internet:As
00000000-0000-0000-0000-000000000000is not a valid subscription ID, this error is triggered.Repro
Replace
azure-cli/.azure-pipelines/templates/automation_test.yml
Lines 16 to 20 in 5df0938
with
so that
test_mysql_flexible_server_vnet_mgmt_supplied_subnet_id_in_different_rgis endlessly retried until failure.The debug logs shows execution details:
Notice that
LROPollerhadn't finished yet andMainThreadalready started a new request.