Skip to content

Commit 8ec551a

Browse files
ewertonsCopilot
andcommitted
fix: validate connection string before starting the broker process
Addresses review feedback on #1245. In mean_time_recover_with_docker.py the environment check sat after process_docker.start() and a five second sleep, so an unset IOTHUB_DEVICE_CONNECTION_STRING raised only once the container restart experiment was already running, leaving the parent waiting on a live non-daemon child. The check now runs first thing in main(), before the certificate is read and before any process is spawned, so the script fails immediately with the clear error. simple_send_message.py already validated before any side effect and is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f8e0a9a commit 8ec551a

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎sdklab/meantimerecovery/mean_time_recover_with_docker.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def timer_done():
125125

126126
async def main():
127127

128+
conn_str = os.getenv("IOTHUB_DEVICE_CONNECTION_STRING")
129+
if not conn_str:
130+
raise RuntimeError(
131+
"Set the IOTHUB_DEVICE_CONNECTION_STRING environment variable to the connection "
132+
"string of the device used against the local test broker, e.g. "
133+
"HostName=localhost;DeviceId=devicemtr;SharedAccessKey=<base64 key>"
134+
)
135+
128136
ca_cert = "self_cert_localhost.pem"
129137
certfile = open(ca_cert)
130138
root_ca_cert = certfile.read()
@@ -141,13 +149,6 @@ async def main():
141149

142150
# Do not delete sleep from here. Server needs some time to start.
143151
await asyncio.sleep(5)
144-
conn_str = os.getenv("IOTHUB_DEVICE_CONNECTION_STRING")
145-
if not conn_str:
146-
raise RuntimeError(
147-
"Set the IOTHUB_DEVICE_CONNECTION_STRING environment variable to the connection "
148-
"string of the device used against the local test broker, e.g. "
149-
"HostName=localhost;DeviceId=devicemtr;SharedAccessKey=<base64 key>"
150-
)
151152
device_client = IoTHubDeviceClient.create_from_connection_string(
152153
conn_str, keep_alive=KEEP_ALIVE, server_verification_cert=root_ca_cert
153154
)

0 commit comments

Comments
 (0)