Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

az iot hub monitor-events -n {iothub_name} is not working #26762

Closed afangster closed 1 year ago

afangster commented 1 year ago

Describe the bug

I have run this command in my Azure Cloud Shell and it works fine there. However, it fails when I run it locally on az cli.

Related command

az iot hub monitor-events -n {iothub_name}

Errors

The command failed with the following error. Errors:

Starting event monitor, use ctrl-c to stop...
ErrorCodes.UnknownError: Connection in an unexpected error state.
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:

More details when run az iot hub monitor-events --login {connection string}:

ErrorCodes.UnknownError: Connection in an unexpected error state.
Traceback (most recent call last):
...
azure-iot\azext_iot\operations\hub.py", line 2548, in iot_hub_monitor_events
    _iot_hub_monitor_events(
...
...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 947, in receive_message_batch_async
    receiving = await self.do_work_async()
...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 374, in do_work_async
    if not await self.client_ready_async():
...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 359, in client_ready_async
    await self._connection.work_async()
...\cliextensions\azure-iot\uamqp\async_ops\connection_async.py", line 129, in work_async
    raise self._error
uamqp.errors.ConnectionClose: ErrorCodes.UnknownError: Connection in an unexpected error state.

Issue script & Debug output

Running az iot hub monitor-event -n {name} --debug:

cli.knack.cli: Command arguments: ['iot', 'hub', 'monitor-events', '-n', '{name}', '--debug']
...
uamqp.c_uamqp: Destroying XIO
uamqp.c_uamqp: Destroying XIO
uamqp.c_uamqp: Destroying SASLMechanism
uamqp.async_ops.connection_async: Connection shutdown complete ...
uamqp: Deinitializing platform.
uamqp.async_ops.connection_async: Finished exiting connection ...
cli.azext_iot.monitor.telemetry: [ConnectionClose('ErrorCodes.UnknownError: Connection in an unexpected error state.'), ConnectionClose('ErrorCodes.UnknownError: Connection in an unexpected error state.')]
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "...\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2548, in iot_hub_monitor_events
    _iot_hub_monitor_events(
  File "...\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2689, in _iot_hub_monitor_events
    start_single_monitor(
  File "...\.azure\cliextensions\azure-iot\azext_iot\monitor\telemetry.py", line 34, in start_single_monitor
    return start_multiple_monitors(
  File "...\.azure\cliextensions\azure-iot\azext_iot\monitor\telemetry.py", line 94, in start_multiple_monitors
    raise RuntimeError(errors[0])
RuntimeError: ErrorCodes.UnknownError: Connection in an unexpected error state.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\..\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2567, in iot_hub_monitor_events
    raise CLIInternalError(e)
azure.cli.core.azclierror.CLIInternalError: ErrorCodes.UnknownError: Connection in an unexpected error state.

cli.azure.cli.core.azclierror: ErrorCodes.UnknownError: Connection in an unexpected error state.
az_command_data_logger: ErrorCodes.UnknownError: Connection in an unexpected error state.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x...>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 2.883 seconds (init: 0.711, invoke: 2.172)
cli.azure.cli.core.decorators: Suppress exception:
Traceback (most recent call last):
  File "D:\...\cli\Lib\site-packages\azure/cli/__main__.py", line 62, in <module>
  File "D:\...\cli\Lib\site-packages\azure/cli/__main__.py", line 55, in <module>
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\...\cli\Lib\site-packages\azure/cli/core/decorators.py", line 79, in _wrapped_func
  File "D:\...\cli\Lib\site-packages\azure/cli/core/telemetry.py", line 122, in generate_payload
  File "json\__init__.py", line 238, in dumps
  File "json\encoder.py", line 199, in encode
  File "json\encoder.py", line 257, in iterencode
  File "json\encoder.py", line 179, in default
TypeError: Object of type RuntimeError is not JSON serializable

telemetry.main: Split cli events and extra events failure: the JSON object must be str, bytes or bytearray, not NoneType
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:
Error in sys.excepthook:

Original exception was:

Expected behavior

I expected to see a live updated list of my sensor data as I did when running it on Azure Cloud Shell. Example as follows:

{
    "event": {
        "origin": "----",
        "module": "",
        "interface": "----",
        "component": "----",
        "payload": "{data here}"
    }
}

Environment Summary

Additional context

I don't think it's a port issue? I checked and they are, quote-unquote 'allowed through the network'.

yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.

ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/azure-iot-cli-triage.

Issue Details
### Describe the bug I have run this command in my Azure Cloud Shell and it works fine there. However, it fails when I run it locally on az cli. ### Related command `az iot hub monitor-events -n {iothub_name}` ### Errors The command failed with the following error. Errors: ``` Starting event monitor, use ctrl-c to stop... ErrorCodes.UnknownError: Connection in an unexpected error state. Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: ``` More details when run `az iot hub monitor-events --login {connection string} `: ``` ErrorCodes.UnknownError: Connection in an unexpected error state. Traceback (most recent call last): ... azure-iot\azext_iot\operations\hub.py", line 2548, in iot_hub_monitor_events _iot_hub_monitor_events( ... ...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 947, in receive_message_batch_async receiving = await self.do_work_async() ...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 374, in do_work_async if not await self.client_ready_async(): ...\cliextensions\azure-iot\uamqp\async_ops\client_async.py", line 359, in client_ready_async await self._connection.work_async() ...\cliextensions\azure-iot\uamqp\async_ops\connection_async.py", line 129, in work_async raise self._error uamqp.errors.ConnectionClose: ErrorCodes.UnknownError: Connection in an unexpected error state. ``` ### Issue script & Debug output Running `az iot hub monitor-event -n {name} --debug`: ``` cli.knack.cli: Command arguments: ['iot', 'hub', 'monitor-events', '-n', '{name}', '--debug'] ... uamqp.c_uamqp: Destroying XIO uamqp.c_uamqp: Destroying XIO uamqp.c_uamqp: Destroying SASLMechanism uamqp.async_ops.connection_async: Connection shutdown complete ... uamqp: Deinitializing platform. uamqp.async_ops.connection_async: Finished exiting connection ... cli.azext_iot.monitor.telemetry: [ConnectionClose('ErrorCodes.UnknownError: Connection in an unexpected error state.'), ConnectionClose('ErrorCodes.UnknownError: Connection in an unexpected error state.')] cli.azure.cli.core.azclierror: Traceback (most recent call last): File "...\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2548, in iot_hub_monitor_events _iot_hub_monitor_events( File "...\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2689, in _iot_hub_monitor_events start_single_monitor( File "...\.azure\cliextensions\azure-iot\azext_iot\monitor\telemetry.py", line 34, in start_single_monitor return start_multiple_monitors( File "...\.azure\cliextensions\azure-iot\azext_iot\monitor\telemetry.py", line 94, in start_multiple_monitors raise RuntimeError(errors[0]) RuntimeError: ErrorCodes.UnknownError: Connection in an unexpected error state. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\a\_work\1\s\build_scripts\windows\artifacts\\cli\Lib\site-packages\knack/cli.py", line 233, in invoke File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__ File "D:\...\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler File "C:\..\.azure\cliextensions\azure-iot\azext_iot\operations\hub.py", line 2567, in iot_hub_monitor_events raise CLIInternalError(e) azure.cli.core.azclierror.CLIInternalError: ErrorCodes.UnknownError: Connection in an unexpected error state. cli.azure.cli.core.azclierror: ErrorCodes.UnknownError: Connection in an unexpected error state. az_command_data_logger: ErrorCodes.UnknownError: Connection in an unexpected error state. cli.knack.cli: Event: Cli.PostExecute [] az_command_data_logger: exit code: 1 cli.__main__: Command ran in 2.883 seconds (init: 0.711, invoke: 2.172) cli.azure.cli.core.decorators: Suppress exception: Traceback (most recent call last): File "D:\...\cli\Lib\site-packages\azure/cli/__main__.py", line 62, in File "D:\...\cli\Lib\site-packages\azure/cli/__main__.py", line 55, in SystemExit: 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\...\cli\Lib\site-packages\azure/cli/core/decorators.py", line 79, in _wrapped_func File "D:\...\cli\Lib\site-packages\azure/cli/core/telemetry.py", line 122, in generate_payload File "json\__init__.py", line 238, in dumps File "json\encoder.py", line 199, in encode File "json\encoder.py", line 257, in iterencode File "json\encoder.py", line 179, in default TypeError: Object of type RuntimeError is not JSON serializable telemetry.main: Split cli events and extra events failure: the JSON object must be str, bytes or bytearray, not NoneType Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: Error in sys.excepthook: Original exception was: ``` ### Expected behavior I expected to see a live updated list of my sensor data as I did when running it on Azure Cloud Shell. Example as follows: ``` { "event": { "origin": "----", "module": "", "interface": "----", "component": "----", "payload": "{data here}" } } ``` ### Environment Summary - OS: [Windows 10] - Shell: [powershell] - Az CLI version: [2.49.0] - azure-iot extension version: [0.21.3] - Python (windows): [3.10.10] ### Additional context I don't think it's a port issue? I checked and they are, quote-unquote 'allowed through the network'.
Author: afangster
Assignees: -
Labels: `bug`, `Service Attention`, `IotHub`, `customer-reported`, `IoT`, `IoT/CLI`, `CXP Attention`, `Auto-Assign`
Milestone: -
vilit1 commented 1 year ago

Since the issue is reported in the extension already (https://github.com/Azure/azure-iot-cli-extension/issues/672), I will close this.