Emulov
Emulov

Reputation: 153

Tomcat with compression enabled causes error on OS X High Sierra

We have been using Tomcat (v7) on OS X for quite some time now and never experienced any problems. However, after updating the OS to High Sierra, the web applications do not work anymore when compression is enabled in the server.xml.

Chrome constantly shows an ERR_CONTENT_DECODING_FAILED (obviously without any content displaying). When compression is switched off, everything works fine. I assume the root of the problem is Apple's upgrade of zlib in High Sierra. Everything was working fine on Sierra. The Tomcat log files look flawless -- there is no mention of any error occurring there.

Does anyone experience the same issue and managed to fix it or knows of a viable workaround without disabling compression?

Also, it would also be helpful if someone can confirm that newer versions of Tomcat do not experience this issue on High Sierra.

Thanks for your help.

Upvotes: 13

Views: 2754

Answers (5)

ssoward
ssoward

Reputation: 540

Our workaround for local dev: We use spring boot and have an EmbeddedServletContainerCustomizer. After updated to High Sierra, same issue. The problem only exists for local development, so not something to push to production. As mentioned above we turned off compressing in our MainConfiguration as follows:

    @Bean
    public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainerFactory servletContainer) {
            ((TomcatEmbeddedServletContainerFactory) servletContainer).addConnectorCustomizers(
                    new TomcatConnectorCustomizer() {
                        @Override
                        public void customize(Connector connector) {
                            AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
                            httpProtocol.setCompression("off");
                            httpProtocol.setCompressionMinSize(256);
                            String mimeTypes = httpProtocol.getCompressableMimeTypes();
                            mimeTypes += "," + MediaType.APPLICATION_JSON_VALUE;
                            mimeTypes += "," + "text/css";
                            mimeTypes += "," + "application/javascript";
                            httpProtocol.setCompressableMimeTypes(mimeTypes);
                        }
                    });
        };
    };
}

Upvotes: 0

ips
ips

Reputation: 46

Fyi, OS X users, I tried installing JDK 8u162-ea from http://jdk.java.net/8/, and it did not fix the issue. I think the reason is that, unlike the Windows JDK, the OS X JDK does not bundle zlib, but rather uses the zlib that is included with OS X (/usr/lib/libz.1.dylib). This can be seen by looking at the shared libraries the java executable depends on:

$ otool -L /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java:
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
    /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 55179.0.2)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 45.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.1.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)

So I think we need a fix for this issue from Apple in the form of an update for High Sierra.

Upvotes: 0

PF.
PF.

Reputation: 21

Workarround/Hack for Windows: Unfortunately I am not familiar with OS X, but I am facing the same problem on Windows and have been able to find a little bit dirty solution for it. The deflate.c error has been fixed in 8u162-ea, see https://bugs.openjdk.java.net/browse/JDK-8189789

Unfortunately 8u162-ea may not contain all fixes or is probably not good enough for a production environment.

To fix it under 8u152, download and install the latest update from http://jdk.java.net/8/

Go to the installation folder (for instance C:\Java\jdk8-162-ea\jre\bin\) and copy the zip.dll which contains the fix (see JDK 9 deflate.c fix) and paste it on the same place under the jdk 8u152.

I hope you can find something similar under OS X.

Upvotes: 2

Mark Adler
Mark Adler

Reputation: 112404

This is a bug in how the Java SDK setLevel() method is implemented. It is reported that compressed data resulting from setting the level is discarded by the SDK. That will result in corrupted compressed data. The fix for the bug can be found here, written by xuemingshen.

Upvotes: 7

cedric
cedric

Reputation: 61

Workaround till an actual fix is found for this: turn off compression in your tomcat project's server.xml configuration.

Upvotes: 4

Related Questions