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

Launcher jar left corrupt when bootstrap download "successfully fails" #6654

Open
cbrunnkvist opened this issue Sep 10, 2021 · 3 comments · May be fixed by #6658
Open

Launcher jar left corrupt when bootstrap download "successfully fails" #6654

cbrunnkvist opened this issue Sep 10, 2021 · 3 comments · May be fixed by #6658
Labels
area/runner-script issues around sbt-the-bash-script, or bat script Bug help wanted

Comments

@cbrunnkvist
Copy link

cbrunnkvist commented Sep 10, 2021

steps

# on a fresh install, i.e.
#   rm -rf ~/.sbt/ ~/.cache/
# and with curl in path:
SBT_LAUNCH_REPO=https://www.google.com/nope ../sbt -d ""

problem

Typical situation: we have a private Artifactory, or other local caching server we need to pull dependencies through, or we have the HTTP proxy vars set incorrectly for whatever reason, or as in the example, the $SBT_LAUNCH_REPO value is simply set incorrectly:

Bootstrapping fails and then subsequent invocation of sbt fail immediately because some HTML body e.g. "404 Not Found" was written to the the boot-jarfile:

Error: Invalid or corrupt jarfile /root/.cache/sbt/boot/sbt-launch/1.5.5/sbt-launch-1.5.5.jar

expectation

sbt should detect and cleanup any failed download, not leaveing the system in a state where we are unable to launch sbt again.

notes

This should be fixable by asking curl to exit with fail with non-zero exit code, and checking $? instead of just testing -f.

(man curl)
...
       -f, --fail
              (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable
              scripts  etc to better deal with failed attempts. In normal cases when an HTTP server fails to
              deliver a document, it returns an HTML document stating so (which often also describes why and
              more). This flag will prevent curl from outputting that and return error 22.

              This  method is not fail-safe and there are occasions where non-successful response codes will
              slip through, especially when authentication is involved (response codes 401 and 407).

I have yet to test how this works It fails in a similar fashion when wget is the only client available, but I believe wget at least already considers HTTP errors, and exits with non-zero. But it needs to be checked for.

@eed3si9n eed3si9n added area/runner-script issues around sbt-the-bash-script, or bat script help wanted labels Sep 10, 2021
@eed3si9n
Copy link
Member

Thanks for the report!

I'm guessing the problem is around here?

sbt/sbt

Lines 116 to 126 in d197b5b

download_url () {
local url="$1"
local jar="$2"
mkdir -p $(dirname "$jar") && {
if command -v curl > /dev/null; then
curl --silent -L "$url" --output "$jar"
elif command -v wget > /dev/null; then
wget --quiet -O "$jar" "$url"
fi
} && [[ -f "$jar" ]]
}

If you have some bandwidth to work on this, would you be open to sending a PR for this?

@cbrunnkvist
Copy link
Author

Alright, are there any tests covering this launcher script btw?

cbrunnkvist added a commit to cbrunnkvist/sbt that referenced this issue Sep 13, 2021
@cbrunnkvist cbrunnkvist linked a pull request Sep 13, 2021 that will close this issue
@eed3si9n
Copy link
Member

We have some tests here - https://github.com/sbt/sbt/tree/develop/launcher-package/integration-test/src/test/scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/runner-script issues around sbt-the-bash-script, or bat script Bug help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants