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

Daemon fails when dvc is called via a wrapper script. #4206

Closed
danfischetti opened this issue Jul 14, 2020 · 2 comments · Fixed by #4262
Closed

Daemon fails when dvc is called via a wrapper script. #4206

danfischetti opened this issue Jul 14, 2020 · 2 comments · Fixed by #4262
Assignees
Labels
bug Did we break something? p1-important Important, aka current backlog of things to do

Comments

@danfischetti
Copy link

Bug Report

Currently, our build system is managed with nix , which stores python packages in a non-standard directory structure. To manage this, as part of the installation process, nix will wrap any executables provided by a package in a wrapper script which sets up the proper environment for that script.

The issue is that the daemon (which is trying to start the updater process on every command) tries to execute sys.argv[0] as a python script, even though it's a shell script, leading to a syntax error.

Here are the lines in question.

dvc/dvc/daemon.py

Lines 90 to 93 in c1b04b8

cmd = [sys.executable]
if not is_binary():
cmd += [sys.argv[0]]
cmd += ["daemon", "-q"] + args

Here's what our wrapper script looks like

#! /nix/store/z1l2n01xdfcm9bkkir83c32mkpvv51zq-bash-4.4-p23/bin/bash -e
export PATH='/nix/store/vhivkaa093jrfb0lfkhf2dl6qkzzhb70-python3-3.6.10/bin:/nix/store/gsb1a6b9nyzmfwxnsalgf5w62bmi83hr-python3.6-dvc-1.1.1/bin:/nix/store/7vvn623206kr6kj8sp6260qmq4kgmvz8-python3.6-distro-1.5.0/bin:/nix/store/p2vylslfgi6p7rd87ai3h6xrhgqd6idz-python3.6-flatten-json-0.1.7/bin:/nix/store/fmnzmxwin3d0981r5yj1jq7kiyljdahp-git-2.26.1/bin:/nix/store/xpcpx849dy54x1r3m8hsv0r7vsxf7iv4-python3.6-future-0.18.2/bin:/nix/store/fladadzc5zcdgpj812mqjyh54lx1n18v-python3.6-jsonpath-ng-1.5.1/bin:/nix/store/05g6dph7rwnw8f3g57pjg5r4rrs2ybvj-python3.6-chardet-3.0.4/bin:/nix/store/4snfznrv0f8zvz7qh9si9nbbh8lx6228-python3.6-setuptools-45.2.0/bin:/nix/store/dz78l5d7zpvbdxvps774ni2f18qz7b00-python3.6-shtab-1.1.0/bin:/nix/store/ak2qwj9l94hvbyqpavlmcsf832ci3q2n-python3.6-tabulate-0.8.7/bin:/nix/store/xs4xkyc66s7zpd7dr5lb8h2h34krnyhn-python3.6-tqdm-4.45.0/bin'${PATH:+':'}$PATH
export PYTHONNOUSERSITE='true'
exec -a "$0" "/nix/store/gsb1a6b9nyzmfwxnsalgf5w62bmi83hr-python3.6-dvc-1.1.1/bin/.dvc-wrapped"  "$@"

and the resulting syntax error that shows up for every command

$ dvc status
  File "/nix/store/gsb1a6b9nyzmfwxnsalgf5w62bmi83hr-python3.6-dvc-1.1.1/bin/dvc", line 2
    export PATH='/nix/store/vhivkaa093jrfb0lfkhf2dl6qkzzhb70-python3-3.6.10/bin:/nix/store/gsb1a6b9nyzmfwxnsalgf5w62bmi83hr-python3.6-dvc-1.1.1/bin:/nix/store/7vvn623206kr6kj8sp6260qmq4kgmvz8-python3.6-di
stro-1.5.0/bin:/nix/store/p2vylslfgi6p7rd87ai3h6xrhgqd6idz-python3.6-flatten-json-0.1.7/bin:/nix/store/fmnzmxwin3d0981r5yj1jq7kiyljdahp-git-2.26.1/bin:/nix/store/xpcpx849dy54x1r3m8hsv0r7vsxf7iv4-python3.6
-future-0.18.2/bin:/nix/store/fladadzc5zcdgpj812mqjyh54lx1n18v-python3.6-jsonpath-ng-1.5.1/bin:/nix/store/05g6dph7rwnw8f3g57pjg5r4rrs2ybvj-python3.6-chardet-3.0.4/bin:/nix/store/4snfznrv0f8zvz7qh9si9nbbh8
lx6228-python3.6-setuptools-45.2.0/bin:/nix/store/dz78l5d7zpvbdxvps774ni2f18qz7b00-python3.6-shtab-1.1.0/bin:/nix/store/ak2qwj9l94hvbyqpavlmcsf832ci3q2n-python3.6-tabulate-0.8.7/bin:/nix/store/xs4xkyc66s7
zpd7dr5lb8h2h34krnyhn-python3.6-tqdm-4.45.0/bin'${PATH:+':'}$PATH
              ^
SyntaxError: invalid syntax

^CERROR: interrupted by the user

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!

Please provide information about your setup

Output of dvc version:

$ dvc version
DVC version: 1.1.1
Python version: 3.6.10
Platform: Linux-4.4.0-141-generic-x86_64-with-debian-stretch-sid
Binary: False
Package: pip
Supported remotes: gs, hdfs, http, https
Cache: reflink - not supported, hardlink - supported, symlink - supported
Filesystem type (cache directory): ('lustre', '172.16.1.1@o2ib:/es0')
Repo: dvc, git
Filesystem type (workspace): ('lustre', '172.16.1.1@o2ib:/es0')

Additional Information (if any):

If applicable, please also provide a --verbose output of the command, eg: dvc add --verbose.

@triage-new-issues triage-new-issues bot added the triage Needs to be triaged label Jul 14, 2020
@efiop
Copy link
Contributor

efiop commented Jul 14, 2020

Hi @danfischetti !

The argv[0] issue is #4165 .

Updater related to #1894 , might've been a good enough workaround if we had it, but we don't 🙁

We'll take a closer look ASAP and will get back to you. Thanks for the feedback!

@efiop efiop added the bug Did we break something? label Jul 14, 2020
@triage-new-issues triage-new-issues bot removed the triage Needs to be triaged label Jul 14, 2020
@efiop efiop added the p1-important Important, aka current backlog of things to do label Jul 14, 2020
@efiop efiop self-assigned this Jul 14, 2020
efiop added a commit to efiop/dvc that referenced this issue Jul 23, 2020
We used `Popen` just to provide a general way of launching our daemons
on both Windows and *nix, but it is causing us issues when dvc is
launched from some exotic places (like nix package) or through `main()`
helper from a script that is not dvc.

This patch makes us just use `main()` directly in our double-forked
process.

Windows implementation has to use the `Popen` mechanism, because this is
the only way to daemonize a process on Windows. This means that dvc on
Windows is still susceptible to this problem, but there is nothing we
can do about it right now :(

Fixes iterative#4206
Fixes iterative#4165
efiop added a commit that referenced this issue Jul 23, 2020
We used `Popen` just to provide a general way of launching our daemons
on both Windows and *nix, but it is causing us issues when dvc is
launched from some exotic places (like nix package) or through `main()`
helper from a script that is not dvc.

This patch makes us just use `main()` directly in our double-forked
process.

Windows implementation has to use the `Popen` mechanism, because this is
the only way to daemonize a process on Windows. This means that dvc on
Windows is still susceptible to this problem, but there is nothing we
can do about it right now :(

Fixes #4206
Fixes #4165
@efiop
Copy link
Contributor

efiop commented Jul 23, 2020

@danfischetti 1.2.0 is out with the fix. Please give it a shot and let us know how it goes 🙂 Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Did we break something? p1-important Important, aka current backlog of things to do
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants