-
Notifications
You must be signed in to change notification settings - Fork 82
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
[FIX] Add a timeout when trying to retrieve dcm2bids version #154
Conversation
Hi @po09i, Thank you for your PR. I'm not able to replicate the issue on my laptop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the PR on my machine and when I'm offline, I get an error:
Thus, I'm suggesting we ping
first, then curl
.
For some reason, I couldn't suggest changes throughout the files, so it needs a bit of tidying.
INFO:dcm2bids.dcm2bids:moving acquisitions into BIDS folder
DEBUG:dcm2bids.version:Checking latest version of unfmontreal/Dcm2Bids was not possible
Traceback (most recent call last):
File "/home/sam/Projects/Dcm2Bids/dcm2bids/version.py", line 43, in check_github_latest
output = check_output(shlex.split("curl --silent " + url), timeout=timeout)
File "/home/sam/miniconda3/envs/dcm2bids-dev/lib/python3.10/subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/home/sam/miniconda3/envs/dcm2bids-dev/lib/python3.10/subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['curl', '--silent', 'https://github.com/unfmontreal/Dcm2Bids/releases/latest']' returned non-zero exit status 6.
DEBUG:dcm2bids.version:Checking latest version of rordenlab/dcm2niix was not possible
Traceback (most recent call last):
File "/home/sam/Projects/Dcm2Bids/dcm2bids/version.py", line 43, in check_github_latest
output = check_output(shlex.split("curl --silent " + url), timeout=timeout)
File "/home/sam/miniconda3/envs/dcm2bids-dev/lib/python3.10/subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/home/sam/miniconda3/envs/dcm2bids-dev/lib/python3.10/subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['curl', '--silent', 'https://github.com/rordenlab/dcm2niix/releases/latest']' returned non-zero exit status 6.
dcm2bids/version.py
Outdated
output = check_output(shlex.split("curl --silent " + url), timeout=timeout) | ||
except: | ||
logger.debug( | ||
"Checking latest version of %s was not possible", githubRepo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output = check_output(shlex.split("curl --silent " + url), timeout=timeout) | |
except: | |
logger.debug( | |
"Checking latest version of %s was not possible", githubRepo, | |
try: | |
if os.name == "nt": | |
check_call(shlex.split("ping -n 1 8.8.8.8"), | |
stdout=DEVNULL, | |
stderr=STDOUT, | |
timeout=timeout) | |
else: | |
check_call(shlex.split("ping -c 1 8.8.8.8"), | |
stdout=DEVNULL, | |
stderr=STDOUT, | |
timeout=timeout) | |
except: | |
logger.info(f"Checking latest version of {githubRepo} was not possible") | |
logger.debug("Can't connect to internet", exc_info=True) | |
return | |
try: | |
output = check_output(shlex.split("curl --silent " + url), timeout=timeout) | |
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to import
from subprocess import check_output, PIPE, check_call, STDOUT, DEVNULL
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is the result of the following line while using the -l DEBUG
option. It displayed the error but the code handled it.
logger.debug("Checking latest version of %s was not possible", githubRepo, exc_info=True)
When we remove the -l DEBUG
, we don't see the error message.
I believe 'pinging' adds an extra layer and extra timeout time for no added benefit. I have opted not to add it until further feedback. However, I have split it up like you suggest to have feedback in 'normal' use cases and output the error message in debug mode:
logger.info(f"Checking latest version of {githubRepo} was not possible")
logger.debug("Can't connect to internet", exc_info=True)
Here are the different outputs for different use cases (I'm only including the last lines of the output log to not clog up this already big comment):
--No extra output--
Note: The error messages are there for debug purposes, they are not an actual error. |
I agree that adding the I don't have strong feeling about it though so I will let @arnaudbore decide 😁 |
Good point about the empty except clause, I can add both exceptions in the except clause so that we follow proper guidelines. |
Since I could separated the exceptions, I wrote a different error message for the timeout. Since the timeout is self explanatory, I removed the output of the error message. Here is the updated output following the comments:
|
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
=========================================
Coverage ? 68.00%
=========================================
Files ? 10
Lines ? 675
Branches ? 108
=========================================
Hits ? 459
Misses ? 185
Partials ? 31
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
Description
This PR adresses #149.
There is a bug that causes dcm2bids to hang when your computer is connected via ethernet to another device, but that device does not provide internet. The bug occurs when fetching the version of dcm2bids or dcm2niix. To fix this, a timeout is added to prevent hanging. While investigating, I noticed the
internet()
function always returnsTrue
and is not necessary, so it was removed. In more details this PR:timeout
option when callingcheck_github_latest()
to prevent hanging indefinitelyinternet()
function as it does nothing and is not usefulinternet()
functionNote:
We realized the problem does not occur for everyone, it happens when using a vpn, or at least on Cisco anyconnect.. See this #149 (comment) for more detail.
To replicate the problem scenario
Linked issues
Fixes #149