Corrupted XLSX, but JSON and CSV are fine

Hi!

There are no errors on Admin/Troubleshooting/Logs when loading the question or downloading.

Downloading either JSON or CSV works fine and I can see the intended data.
But when I download any .xlsx, the file can't be opened. Opening the file with a text editor shows the stack trace at the bottom.
Below I paste the diagnostic.

{
  "browser-info": {
    "language": "en",
    "platform": "Win32",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
    "vendor": "Google Inc."
  },
  "system-info": {
    "file.encoding": "UTF-8",
    "java.runtime.name": "OpenJDK Runtime Environment",
    "java.runtime.version": "11.0.12+7-LTS",
    "java.vendor": "Azul Systems, Inc.",
    "java.vendor.url": "http://www.azul.com/",
    "java.version": "11.0.12",
    "java.vm.name": "OpenJDK 64-Bit Server VM",
    "java.vm.version": "11.0.12+7-LTS",
    "os.name": "Linux",
    "os.version": "4.15.0-162-generic",
    "user.language": "en",
    "user.timezone": "GMT"
  },
  "metabase-info": {
    "databases": [
      "sqlserver"
    ],
    "hosting-env": "unknown",
    "application-database": "postgres",
    "application-database-details": {
      "database": {
        "name": "PostgreSQL",
        "version": "10.17"
      },
      "jdbc-driver": {
        "name": "PostgreSQL JDBC Driver",
        "version": "42.2.23"
      }
    },
    "run-mode": "prod",
    "version": {
      "date": "2022-04-07",
      "tag": "v0.42.4",
      "branch": "release-x.42.x",
      "hash": "7c3ce2d"
    },
    "settings": {
      "report-timezone": "Europe/Berlin"
    }
  }
}

And the .xlsx content.

{"via":[{"type":"java.lang.InternalError","message":"java.lang.reflect.InvocationTargetException","at":["sun.font.FontManagerFactory$1","run","FontManagerFactory.java",86]},{"type":"java.lang.reflect.InvocationTargetException","at":["jdk.internal.reflect.NativeConstructorAccessorImpl","newInstance0","NativeConstructorAccessorImpl.java",-2]},{"type":"java.lang.NullPointerException","at":["sun.awt.FontConfiguration","getVersion","FontConfiguration.java",1262]}],"trace":[["sun.awt.FontConfiguration","getVersion","FontConfiguration.java",1262],["sun.awt.FontConfiguration","readFontConfigFile","FontConfiguration.java",225],["sun.awt.FontConfiguration","init","FontConfiguration.java",107],["sun.awt.X11FontManager","createFontConfiguration","X11FontManager.java",719],["sun.font.SunFontManager$2","run","SunFontManager.java",379],["java.security.AccessController","doPrivileged","AccessController.java",-2],["sun.font.SunFontManager","<init>","SunFontManager.java",324],["sun.awt.FcFontManager","<init>","FcFontManager.java",35],["sun.awt.X11FontManager","<init>","X11FontManager.java",56],["jdk.internal.reflect.NativeConstructorAccessorImpl","newInstance0","NativeConstructorAccessorImpl.java",-2],["jdk.internal.reflect.NativeConstructorAccessorImpl","newInstance","NativeConstructorAccessorImpl.java",62],["jdk.internal.reflect.DelegatingConstructorAccessorImpl","newInstance","DelegatingConstructorAccessorImpl.java",45],["java.lang.reflect.Constructor","newInstance","Constructor.java",490],["sun.font.FontManagerFactory$1","run","FontManagerFactory.java",84],["java.security.AccessController","doPrivileged","AccessController.java",-2],["sun.font.FontManagerFactory","getInstance","FontManagerFactory.java",74],["java.awt.Font","getFont2D","Font.java",497],["java.awt.Font","canDisplayUpTo","Font.java",2250],["java.awt.font.TextLayout","singleFont","TextLayout.java",469],["java.awt.font.TextLayout","<init>","TextLayout.java",530],["org.apache.poi.ss.util.SheetUtil","getDefaultCharWidth","SheetUtil.java",285],["org.apache.poi.xssf.streaming.AutoSizeColumnTracker","<init>","AutoSizeColumnTracker.java",117],["org.apache.poi.xssf.streaming.SXSSFSheet","<init>","SXSSFSheet.java",89],["org.apache.poi.xssf.streaming.SXSSFWorkbook","createAndRegisterSXSSFSheet","SXSSFWorkbook.java",701],["org.apache.poi.xssf.streaming.SXSSFWorkbook","createSheet","SXSSFWorkbook.java",722],["org.apache.poi.xssf.streaming.SXSSFWorkbook","createSheet","SXSSFWorkbook.java",96],["dk.ative.docjure.spreadsheet$add_sheet_BANG_","invokeStatic","spreadsheet.clj",312],["dk.ative.docjure.spreadsheet$add_sheet_BANG_","invoke","spreadsheet.clj",308],["metabase.query_processor.streaming.xlsx$fn__38280","invokeStatic","xlsx.clj",464],["metabase.query_processor.streaming.xlsx$fn__38280","invoke","xlsx.clj",461],["clojure.lang.MultiFn","invoke","MultiFn.java",234],["metabase.query_processor.streaming$streaming_context","invokeStatic","streaming.clj",141],["metabase.query_processor.streaming$streaming_context","invoke","streaming.clj",134],["metabase.query_processor.streaming$streaming_context","invokeStatic","streaming.clj",147],["metabase.query_processor.streaming$streaming_context","invoke","streaming.clj",134],["metabase.query_processor.streaming$streaming_response_STAR_$fn__38430$fn__38431","invoke","streaming.clj",162],["metabase.query_processor.streaming$streaming_response_STAR_$fn__38430","invoke","streaming.clj",161],["clojure.lang.AFn","applyToHelper","AFn.java",156],["clojure.lang.AFn","applyTo","AFn.java",144],["clojure.core$apply","invokeStatic","core.clj",667],["clojure.core$with_bindings_STAR_","invokeStatic","core.clj",1977],["clojure.core$with_bindings_STAR_","doInvoke","core.clj",1977],["clojure.lang.RestFn","applyTo","RestFn.java",142],["clojure.core$apply","invokeStatic","core.clj",671],["clojure.core$bound_fn_STAR_$fn__5767","doInvoke","core.clj",2007],["clojure.lang.RestFn","invoke","RestFn.java",421],["metabase.async.streaming_response$do_f_STAR_","invokeStatic","streaming_response.clj",65],["metabase.async.streaming_response$do_f_STAR_","invoke","streaming_response.clj",63],["metabase.async.streaming_response$do_f_async$task__26899","invoke","streaming_response.clj",84],["clojure.lang.AFn","run","AFn.java",22],["java.util.concurrent.Executors$RunnableAdapter","call","Executors.java",515],["java.util.concurrent.FutureTask","run","FutureTask.java",264],["java.util.concurrent.ThreadPoolExecutor","runWorker","ThreadPoolExecutor.java",1128],["java.util.concurrent.ThreadPoolExecutor$Worker","run","ThreadPoolExecutor.java",628],["java.lang.Thread","run","Thread.java",829]],"_status":500} ```

Hi @jsacra
It is caused by missing font libraries in Java: https://discourse.metabase.com/search?q=FontManagerFactory%20order%3Alatest
Depending on your server, try installing apt install libfontconfig1

It's running in a Linux Azure App Service where we place the metabase.jar, do you have an idea of how could I run this install command?

@jsacra No, try contacting their support.

I'm not getting a response from them. But I did find that it's running on a Docker container that is initialized on startup.
How can I access the container so I can then run commands in the container?

2022-04-20T14:48:46.398Z INFO  - Initiating warmup request to container bh-tool-metabase_0_42ac7a84 for site bh-tool-metabase
2022-04-20T14:49:04.016Z INFO  - Waiting for response to warmup request for container bh-tool-metabase_0_42ac7a84. Elapsed time = 17.6187249 sec
2022-04-20T14:49:17.849Z INFO  - Container bh-tool-metabase_0_42ac7a84 for site bh-tool-metabase initialized successfully and is ready to serve requests.
2022-04-20T14:49:32.891Z ERROR - Container for bh-tool-metabase_0_42ac7a84 site bh-tool-metabase is unhealthy, Stopping site.
2022-04-20T14:49:32.892Z INFO  - Stopping site bh-tool-metabase because it is not healthy.
2022-04-20T14:49:33.441Z INFO  - Pulling image: mcr.microsoft.com/azure-app-service/java:11-java11_210819211055
2022-04-20T14:49:33.565Z INFO  - 11-java11_210819211055 Pulling from azure-app-service/java
2022-04-20T14:49:33.566Z INFO  -  Digest: sha256:41488ea259c0fb52296454db25614312b8dd6e98472d02e8da68a226efa626e1
2022-04-20T14:49:33.567Z INFO  -  Status: Image is up to date for mcr.microsoft.com/azure-app-service/java:11-java11_210819211055
2022-04-20T14:49:33.571Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2022-04-20T14:49:33.593Z INFO  - Starting container for site
2022-04-20T14:49:33.593Z INFO  - docker run -d -p 3760:80 --name bh-tool-metabase_0_797599f1 -e WEBSITE_SITE_NAME=bh-tool-metabase -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=bh-tool-metabase.azurewebsites.net -e WEBSITE_INSTANCE_ID=3efc57a1b260493e3bde4d42c7223e5fd634f4f43671252c515daa9092cdc5d5 -e HTTP_LOGGING_ENABLED=1 mcr.microsoft.com/azure-app-service/java:11-java11_210819211055 java -Xmx5g -Djava.net.preferIPv4Stack=true -jar /home/site/wwwroot/metabase.jar 

2022-04-20T14:49:34.663Z INFO  - Initiating warmup request to container bh-tool-metabase_0_797599f1 for site bh-tool-metabase
2022-04-20T14:49:49.755Z INFO  - Waiting for response to warmup request for container bh-tool-metabase_0_797599f1. Elapsed time = 15.0923591 sec
2022-04-20T14:50:04.893Z INFO  - Waiting for response to warmup request for container bh-tool-metabase_0_797599f1. Elapsed time = 30.2297946 sec
2022-04-20T14:50:07.279Z INFO  - Container bh-tool-metabase_0_797599f1 for site bh-tool-metabase initialized successfully and is ready to serve requests. ```

@jsacra I don't know. I would recommend that you use a different hosting provider, which provides more flexibility. You won't have this problem with the official Docker images.

For anyone else facing a similar issue:

Azure App Service loads up a container with the indicated image. If you access the app service's SSH, you will be connected to the container.

For a one-time update, you can directly run updates from the SSH terminal.
Not sure why but needed to include these options to install the package successfully:
apk add --no-cache --virtual libfontconfig1 ttf-dejavu
Also, for the web app to read these packages correctly, you have to add an Application Setting: "LD_LIBRARY_PATH" with value="/usr/bin" (this is the directory where installed packages are stored).

For a persistent solution:
Azure App Services offer two ways to configure container images: startup file (a .sh script) or a startup command. I was personally unable to configure the startup file correctly, so I stuck with the startup command - I FTP'd a startup.sh script, and in the startup command ran that script, like so :
./home/site/wwwroot/startup.sh

Inside the script are the dependencies installation and running the .jar:

apk add --no-cache --virtual libfontconfig1 ttf-dejavu
java -Xmx5g -Djava.net.preferIPv4Stack=true -jar /home/site/wwwroot/metabase.jar```
1 Like