Replies: 1 comment 1 reply
-
@ronf yes, I did delete my comment as I finally read the code and saw what you are explaining and did just that, removed the checking of the return code outside of the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I received a question about a problem reliably getting a return code back from an exiting SSH session. It's basically a race condition between the server sending the exit status and the client reading it. More specifically, the following code will have this problem:
If the code waiting for output returns when EOF is received and the client tried to get the returncode right away, the exit status for the process may not have been received yet. To fix this, you can add an
await process.wait_closed()
before reading returncode. This should avoid the race condition with the server sending the status.The use of
async with
callswait_closed()
on the process, but it does so only after reading returncode (when exiting the block), which is where the race comes into play. By doing thewait_closed()
explicitly before reading the returncode, you can avoid this problem. The other alternative would be to do something like:By moving the read of returncode out of the
async with
, you can be sure any exit status has been received.@RobertDeRose You deleted your original question, so you may have already figured this out, but I thought it would be good to capture as a note (without including details of your original code) in case others run into this issue. I hope you don't mind my doing so. I would have tried to contact you directly first, but I couldn't find your contact info. Let me know if you'd like me to remove references to you from this discussion.
Beta Was this translation helpful? Give feedback.
All reactions