[ https://issues.apache.org/jira/browse/SOLR-17029?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17775015#comment-17775015 ]
Chris M. Hostetter commented on SOLR-17029: ------------------------------------------- As noted by Kevin Risden on the users' mailing list... {noformat} I ran `shellcheck solr/bin/solr` and one of the warnings jumped out as potentially relevant. I haven't had a chance to check it further yet. In solr/bin/solr line 1224: SOLR_OPTS=(${SOLR_OPTS:-}) ^------------^ SC2206 (warning): Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. My guess is its being split into an array based on spaces - https://www.shellcheck.net/wiki/SC2206 has more details about options. {noformat} ...it's definitely getting split into an array based on spaces – but (w/o digging to much into the archeology of how the code evolved) that seems like a very intentional choice based on where/how the "new" {{SOLR_OPTS}} is used internally in {{bin/solr}} as an array to append additional script derived options later... This is what 9.3 looks like... {noformat} SOLR_OPTS=(${SOLR_OPTS:-}) ... # pass thru any opts that begin with -D (java system props) SOLR_OPTS+=("$1") ... # Solr modules option if [[ -n "${SOLR_MODULES:-}" ]] ; then SOLR_OPTS+=("-Dsolr.modules=$SOLR_MODULES") fi ... lots more examples like SOLR_MODULES .... if [ -n "${SOLR_OPTS:-}" ]; then echo -e " SOLR_OPTS = ${SOLR_OPTS[*]}" fi ... SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE_ARR[@]}" "${GC_LOG_OPTS[@]}" "${IP_ACL_OPTS[@]}" \ "${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" ${SOLR_LOG_LEVEL_OPT:-} -Dsolr.log.dir="$SOLR_LOGS_DIR" \ "-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \ # '-OmitStackTraceInFastThrow' ensures stack traces in errors, # users who don't care about useful error msgs can override in SOLR_OPTS with +OmitStackTraceInFastThrow "${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" "-XX:-OmitStackTraceInFastThrow" \ # '+CrashOnOutOfMemoryError' ensures that Solr crashes whenever # OOME is thrown. Program operation after OOME is unpredictable. "-XX:+CrashOnOutOfMemoryError" "-XX:ErrorFile=${SOLR_LOGS_DIR}/jvm_crash_%p.log" \ "-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.install.dir=$SOLR_TIP" "-Dsolr.install.symDir=$SOLR_TIP_SYM" \ "-Dsolr.default.confdir=$DEFAULT_CONFDIR" "${LOG4J_CONFIG[@]}" "${SOLR_OPTS[@]}" "${SECURITY_MANAGER_OPTS[@]}" "${SOLR_ADMIN_UI}") {noformat} (I'm guessing at some point someone said "we need an array of options we build up and then later format as a string" w/o considering what/how/where bash cares about whitespace & quoting characters in string/array handling) On the {{main}} & 9x branches the situation is significantly improved by the introduction of a {{SCRIPT_SOLR_OPTS=()}} via SOLR-16970 – so most of the things that get "appended" to the {{SOLR_OPTS}} array on 9x, are now instead appended to the {{SCRIPT_SOLR_OPTS}} array ... but {{SOLR_OPTS}} is still parsed & treated as an array. ---- I'm not bash expert – but FWIW: the "newish" {{@Q}} feature of bash param expansion seems like it would probably be really freaking useful in general for a lot of {{bin/solr}} 's "Give me some raw arguments to pass to the JVM" type behavior... [https://lwn.net/Articles/701009/] ...bash 4.4 was released in sept 2016 – almost exactly 2 years before the minimum JRE we require on branch 9x. I think it's safe to say we can require it as a minimum supported bash. > SOLR_OPTS and '-a' both break with quoted/escaped whitespace > ------------------------------------------------------------ > > Key: SOLR-17029 > URL: https://issues.apache.org/jira/browse/SOLR-17029 > Project: Solr > Issue Type: Bug > Security Level: Public(Default Security Level. Issues are Public) > Reporter: Chris M. Hostetter > Priority: Major > > It's basically impossible to use an quoted/escaped whitespace in SOLR_OPTS. > By the time {{java}} gets the args, the quoted/escaped whitespace has been > treated as a break in the argument list, and the quote characters are treated > as literals characters in the argument values... > {noformat} > $ SOLR_OPTS='-XX:-UseLargePages -Dfoo=bar -Dyak="white space"' ./bin/solr > start -f > Error: Could not find or load main class space" > Caused by: java.lang.ClassNotFoundException: space" > $ SOLR_OPTS="-XX:-UseLargePages -Dfoo=bar -Dyak=white\ space" ./bin/solr > start -f > Error: Could not find or load main class space > Caused by: java.lang.ClassNotFoundException: space > $ SOLR_OPTS='-XX:-UseLargePages -Dfoo=bar "-Dyak=white space"' ./bin/solr > start -f > Error: Could not find or load main class "-Dyak=white > Caused by: java.lang.ClassNotFoundException: "-Dyak=white > {noformat} > The same problem affects the {{-a}} option... > {noformat} > $ SOLR_OPTS='-XX:-UseLargePages -Dfoo=bar' ./bin/solr start -f -a > '-Dyak="white space"' > Error: Could not find or load main class space" > Caused by: java.lang.ClassNotFoundException: space" > {noformat} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org