Skip to content
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

dcm2bids hangs when connected via ethernet without internet #149

Closed
po09i opened this issue Feb 9, 2022 · 6 comments · Fixed by #154
Closed

dcm2bids hangs when connected via ethernet without internet #149

po09i opened this issue Feb 9, 2022 · 6 comments · Fixed by #154

Comments

@po09i
Copy link
Contributor

po09i commented Feb 9, 2022

Bug Description

When scanning at the UNF, we connect to the scanner via ethernet so that a drive can be mounted from the scanner. When running dcm2bids, it hangs and we have to manually cancel the execution. This is the last line shown on the command line.

INFO:dcm2bids.dcm2bids:moving acquisitions into BIDS folder

Note:
We lose our internet connection when connecting via ethernet to mount the drive.

Potential Reasons behind Bug:

Since we don't have internet, but it looks like we are (we are connected via ethernet), I think dcm2bids is hanging trying to retrieve its version in this line.

Command line output

Screen Shot 2022-02-08 at 5 58 21 PM

@po09i
Copy link
Contributor Author

po09i commented Apr 11, 2022

More info

I forked the repo and investigated a bit more.

The internet() function does not work as intended. It always returns True whether I am connected to the internet or not.

Why does it work for usual scenarios?

When not connected to the internet, since if internet() always returns True, we trigger the check_github_latest() function. Since we are not connected to the internet, it raises and error, that error is captured by dcm2bids and handled properly.

Problems with the current method

The problem arises when we are connected via ethernet, without internet. The connection hangs waiting indefinitely for a response. No error is raised because it is waiting for a response that will never come.

Suggestion

  • Remove the internet() function as it does nothing and is not useful
  • Add a timeout option when calling check_github_latest() to prevent hanging indefinitely

@po09i
Copy link
Contributor Author

po09i commented Apr 11, 2022

To replicate the problem

  1. Connect your computer to your router using an ethernet cable
  2. Disconnect from the router the cable providing internet to your router
  3. Run dcm2bids

@SamGuay
Copy link
Member

SamGuay commented Apr 15, 2022

Hi @po09i !

Thanks for the bug report and the accompanying PR. I've investigated the issue on my machine and a virtual machine not connected to ethernet and here's what I got using the latest version with the --log_level DEBUG:

INFO:dcm2bids.sidecar:Sidecars pairing:
INFO:dcm2bids.sidecar:_T1w  <-  007_07-anat_T1w_anat_T1w_19000101111111
INFO:dcm2bids.dcm2bids:moving acquisitions into BIDS folder
DEBUG:dcm2bids.version:Checking latest version of dcm2bids was not possible
DEBUG:dcm2bids.version:internet: False, curl: True
DEBUG:dcm2bids.version:Checking latest version of dcm2niix was not possible
DEBUG:dcm2bids.version:internet: False, curl: True

I noticed it was slightly slower than when connected to internet due to the timeout while checking if it can reach host="8.8.8.8", port=53, timeout=3. It appears the internet() function does work as supposed (ie, returns False when not connected as seen above). dcm2bids was able to move the files after.

I think the issue is not dcm2bids per se but your computer thinking it is connected to internet while it's only connected to a local network through an ethernet port. I think it is important to deal with this as the behaviour seems unpredictable for now on machines which are connected to ethernet but cant reach outside..

That being said, to investigate this further, can you reproduce your issue using the -l DEBUG flag (eg dcm2bids -l DEBUG -d input_dir/ -p 001 -c dcm2bids.conf and paste your output here in a code bloc?

Thanks

@po09i
Copy link
Contributor Author

po09i commented Apr 18, 2022

Thanks for answering @SamGuay!

Here is my output when I run dcm2bids on the latest version of master without internet and not connected via ethernet using -l DEBUG :

INFO:dcm2bids.dcm2niix:Check log file for dcm2niix output
INFO:dcm2bids.sidecar:Sidecars pairing:
INFO:dcm2bids.sidecar:_magnitude1  <-  002_dicoms_gre_field_mapping_PMUlog_20210407174936_e1
INFO:dcm2bids.sidecar:_magnitude2  <-  002_dicoms_gre_field_mapping_PMUlog_20210407174936_e2
INFO:dcm2bids.sidecar:_phase2  <-  003_dicoms_gre_field_mapping_PMUlog_20210407174936_e2_ph
INFO:dcm2bids.sidecar:_unshimmed_e1  <-  006_dicoms_gre_dyn_realtime_shimming_NOSHIM_highRes_run1_20210407174936_e1
INFO:dcm2bids.sidecar:_unshimmed_e2  <-  006_dicoms_gre_dyn_realtime_shimming_NOSHIM_highRes_run1_20210407174936_e2
INFO:dcm2bids.sidecar:_unshimmed_e3  <-  006_dicoms_gre_dyn_realtime_shimming_NOSHIM_highRes_run1_20210407174936_e3
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 "/Users/alexandredastous/Documents/School/Polytechnique/Master/project/Dcm2Bids/dcm2bids/version.py", line 65, in check_github_latest
    output = check_output(shlex.split("curl --silent " + url))
  File "/Users/alexandredastous/miniconda3/envs/dcm2bids/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/alexandredastous/miniconda3/envs/dcm2bids/lib/python3.9/subprocess.py", line 528, 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 "/Users/alexandredastous/Documents/School/Polytechnique/Master/project/Dcm2Bids/dcm2bids/version.py", line 65, in check_github_latest
    output = check_output(shlex.split("curl --silent " + url))
  File "/Users/alexandredastous/miniconda3/envs/dcm2bids/lib/python3.9/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/alexandredastous/miniconda3/envs/dcm2bids/lib/python3.9/subprocess.py", line 528, 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.

As you can see, the error message is within check_github_latest() which is called after the internet() check which is what leads me to believe the internet() function is not behaving as expected...

@po09i
Copy link
Contributor Author

po09i commented Apr 18, 2022

I tried to debug the internet() function. I tried using socket.connect_ex() to see what the output code would be:

def internet(host="8.8.8.8", port=53, timeout=3):
    try:
        socket.setdefaulttimeout(timeout)
        code = socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex((host, port)). # socket.connect_ex()
        logger.debug(code). # Output debug verbose
        return True

    except:
        return False

and got an output code of 0 which is the expected behaviour if there is no error.

DEBUG:dcm2bids.version:0

@po09i
Copy link
Contributor Author

po09i commented Apr 19, 2022

Good news, I found out the problem and why you can't replicate it. I have a VPN installed and even when it is disconnected, it seems to mess up whatever is going on when connecting with a socket. I uninstalled the vpn and I was able to reproduce the expected behaviour.

The VPN I have to use is Cisco AnyConnect Secure Mobility Client and would find it really inconvenient to uninstall the VPN to use dcm2bids. I am not sure if this is a problem for all VPNs...

Proposed solutions:

  • Ask Cisco to fix it (if it's not an inherently VPN problem) --> Never going to get fixed
  • Remove the internet() function entirely and add a timeout in check_github_latest()
  • Other solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants