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

"Invalid extended option" error for legit -X options #5091

Closed
alaz opened this issue Mar 17, 2018 · 10 comments
Closed

"Invalid extended option" error for legit -X options #5091

alaz opened this issue Mar 17, 2018 · 10 comments

Comments

@alaz
Copy link

alaz commented Mar 17, 2018

JRuby version:

$ docker run --rm -it jruby:9-alpine jruby -v
jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [linux-x86_64]

The list of valid -X options:

$ docker run --rm -it jruby:9-alpine jruby '-Xjit?'
jit.threshold=50
jit.max=4096
jit.maxsize=2000
jit.logging=false
jit.logging.verbose=false
jit.dumping=false
jit.logEvery=0
jit.exclude=
jit.debug=false
jit.background=true
jit.kernel=false
ir.jit.passes=null
jit.cache=true
jit.codeCache=null

And here it is an error when specifying any option:

$ docker run --rm -it jruby:9-alpine jruby -Xjit.max=16384 | head
expr: syntax error
jruby: invalid extended option jit.max=16384 (-X will list valid options)

Usage: jruby [switches] [--] [programfile] [arguments]
  -0[octal]         specify record separator (\0, if no argument)
  -a                autosplit mode with -n or -p (splits $_ into $F)
  -c                check syntax only
  -Cdirectory       cd to directory, before executing your script
  -d                set debugging flags (set $DEBUG to true)
  -e 'command'      one line of script. Several -e's allowed. Omit [programfile]

$ docker run --rm -it jruby:9-alpine jruby -Xjit.logging=true | head
expr: syntax error
jruby: invalid extended option jit.logging=true (-X will list valid options)

Usage: jruby [switches] [--] [programfile] [arguments]
  -0[octal]         specify record separator (\0, if no argument)
  -a                autosplit mode with -n or -p (splits $_ into $F)
  -c                check syntax only
  -Cdirectory       cd to directory, before executing your script
  -d                set debugging flags (set $DEBUG to true)
  -e 'command'      one line of script. Several -e's allowed. Omit [programfile]
@BanzaiMan
Copy link
Member

Who's building this Docker image? https://hub.docker.com/_/jruby/ says this is "official", but maybe you should report to https://github.com/cpuguy83/docker-jruby/issues instead, because I don't see the problem on our release.

Output from ./bin/jruby -Xjit.max=16384 -v in the released 9.1.16.0 archive
$ curl -LO https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.1.16.0/jruby-dist-9.1.16.0-bin.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20.4M  100 20.4M    0     0  9365k      0  0:00:02  0:00:02 --:--:-- 9364k
$ tar zxf jruby-dist-9.1.16.0-bin.tar.gz
$ cd jruby-9.1.16.0
$ ./bin/jruby -Xjit.max=16384 -v
jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]

I can reproduce the problem with the Alpine docker image, but not with the jruby image.

This leads me to believe that the problem stems from the difference between Debian and Alpine distros; namely,

expr -- jit.max=16384 : '.*[.]'

works on the former, and fails on the latter. Since Alpine's expr does not respond to --version, it is not a GNU one.

@alaz
Copy link
Author

alaz commented Mar 17, 2018

Oops, I was under impression the image is official indeed. If it's not, but claims so – isn't it a problem?

Thank you.

@BanzaiMan
Copy link
Member

Well, if Alpine's expr does not behave the way expect, perhaps that should be fixed, whether or not this Docker image is "official."

@headius
Copy link
Member

headius commented Mar 17, 2018

I hate to say it but I am thinking we should start pushing an official image with our releases. Issues like this that we can't fix directly will impact people disproportionately.

@alaz
Copy link
Author

alaz commented Mar 18, 2018

Both 9.1.15 and 9.1.16 images inherit from the same Alpine 3.7.0 and jruby script in the former works fine.

The only change to the shell scripts in bin between 9.1.15 and 9.1.16 is this one b617d55 and it was exactly about how expr is being used.

Anyone who would try to pack JRuby 9.1.16 into Alpine (including openjdk:8-jre-alpine) is going to face the same issue.

@alaz alaz reopened this Mar 18, 2018
@headius
Copy link
Member

headius commented Mar 19, 2018

@alaz Are you saying it worked ok in 9.1.15?

A workaround may be to install the native launcher (gem install jruby-launcher) since it uses standard C/++ to parse out these properties.

We'll need a patch for the bash launcher that doesn't regress the FreeBSD fix.

@alaz
Copy link
Author

alaz commented Mar 19, 2018

@headius yes, 9.1.15 accepts arguments w/o problems:

$ docker run --rm jruby:9.1.15-alpine jruby -Xjit.max=16384 --version 
jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [linux-x86_64]

@headius
Copy link
Member

headius commented Mar 19, 2018

Reproduced locally.

@headius
Copy link
Member

headius commented Mar 19, 2018

This patch appears to work on both Darwin and Alpine for me. I'll test Ubuntu shortly.

Edit: wrong patch

diff --git a/bin/jruby.bash b/bin/jruby.bash
index 5c841fedb6..fb090a8818 100755
--- a/bin/jruby.bash
+++ b/bin/jruby.bash
@@ -20,6 +20,14 @@ case "`uname`" in
   MINGW*) jruby.exe "$@"; exit $?;;
 esac
 
+# ----- Determine how to call expr (jruby/jruby#5091) -------------------------
+# On Alpine linux, expr takes no -- arguments, and 'expr --' echoes '--'.
+_expr_dashed=$(expr -- 2>/dev/null)
+if [ "$_expr_dashed" != '--' ] ; then
+  alias expr="expr --"
+fi
+unset _expr_dashed
+
 # ----- Verify and Set Required Environment Variables -------------------------
 if [ -z "$JAVA_VM" ]; then
   JAVA_VM=-client
@@ -244,7 +252,7 @@ do
      # Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
      -X*)
         val=${1:2}
-        if expr -- "$val" : '.*[.]' > /dev/null; then
+        if expr "$val" : '.*[.]' > /dev/null; then
           java_args=("${java_args[@]}" "-Djruby.${val}")
         else
           ruby_args=("${ruby_args[@]}" "-X${val}")

headius added a commit that referenced this issue Mar 19, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
In #5013 we modified our bash script to use -- when calling the
`expr` command, but this form is not supported on Alpine Linux's
version of expr. This patch tests the behavior of `expr --` to
determine which form to use.
@headius
Copy link
Member

headius commented Mar 19, 2018

The fix appears to work on Darwin, Ubuntu, and Alpine. I have committed it and it will be in 9.1.17.

@headius headius closed this as completed Mar 19, 2018
@headius headius added this to the JRuby 9.1.17.0 milestone Mar 19, 2018
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

No branches or pull requests

3 participants