2

This error trace is polluting my logs and I can't find on SA or else what is causing it:

[2022-01-11T04:15:00.144+0100] [] [[1;91mSEVERE[0m] [AS-WEB-CORE-00037] [[1;94mjavax.enterprise.web.core[0m] [tid: _ThreadID=27428 _ThreadName=http-thread-pool::http-listener(331)] [timeMillis: 1641870900144] [levelValue: 1000] [[
  An exception or error occurred in the container during the request processing
java.lang.Exception: Host is not set
    at org.glassfish.grizzly.http.server.util.Mapper.map(Mapper.java:865)
    at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:496)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:309)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:520)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:217)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
    at java.base/java.lang.Thread.run(Thread.java:829)
]]

This is for a JakartaEE app with JSF 2.3 (Faces) running on Payara micro 5.2021.2. If this is of any relevance, here are the parts of the nginx config that redirect the traffic to the app:

upstream payara {
    least_conn;

    server localhost:8080 max_fails=3 fail_timeout=5s;
    server localhost:8181 max_fails=3 fail_timeout=5s;
}

    location /jsf-app-1.0-SNAPSHOT/ {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_no_cache $cookie_nocache  $arg_nocache$arg_comment;
            proxy_no_cache $http_pragma     $http_authorization;
            proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
            proxy_cache_bypass $http_pragma $http_authorization;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host:$server_port;
            add_header Access-Control-Allow-Origin *;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_pass http://payara$request_uri;
    }
    
    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        proxy_no_cache $cookie_nocache  $arg_nocache$arg_comment;
            proxy_no_cache $http_pragma     $http_authorization;
            proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
            proxy_cache_bypass $http_pragma $http_authorization;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host:$server_port;
            add_header Access-Control-Allow-Origin *;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_pass http://payara$request_uri$is_args$args;

   }
seinecle
  • 10,118
  • 14
  • 61
  • 120
  • 1
    is there any reason why you have two `proxy_set_header Host` lines? In case the usual way of accessing your application is a web browser the Host will never be empty. Could you just try to delete `proxy_set_header Host $http_host;` – Timo Stark Jan 19 '22 at 18:47
  • thx! I removed the line and the exception continues. It is possible that other lines from the nginx config files are interferring... – seinecle Jan 21 '22 at 12:05
  • Also this proxy_set_header Host $http_host; turned out to be essential, without it there is an error with http / https pages – seinecle Jan 21 '22 at 13:02
  • I have a strong feeling there is something else confusing your backend. We from NGINX always recommend to use the `$host` variable. So without seeint the full configuration and some error.logs on the NGINX site it is hard to follow. If you want feel free to turn on debugging and share the debug log with me over a channel listed in my profile. Happy to have a look on it – Timo Stark Jan 21 '22 at 16:00

1 Answers1

0

Looks like Grizzly is trying to obtain the hostname from the Host header in the request. Since HTTP 1.1 the Host header is required but if the Host header is set an empty name, Grizzly cannot obtain the name and throws an exception.

The Host request header is set by the HTTP client. But even if the Host header exists but its value is empty due to some reason the exception will be thrown.

Grizzly Code: the code that throws the Exception


According to the Javadocs for Grizzly you can set the default hostname by calling the setDefaultHostName(String defaultHostName) method, but the instance of the Mapper in the HttpHanderChain instance is not exposed. The default value set in HttpHanderChain of the Mapper instance is set to "localhost".

Noah
  • 859
  • 7
  • 17
  • Ok thx! And is there a way I could do a check on the Host header request (and set a value to it if its null) before it is treated by Grizzly? – seinecle Jan 14 '22 at 22:39
  • I've updated my answer to I can include a code example. – Noah Jan 15 '22 at 17:57
  • If it answers your question, please mark it as the accepted answer. – Noah Jan 15 '22 at 17:57
  • thanks for the explanation! I am looking for a solution though. Since the method is not exposed, I am unsure how to proceed. – seinecle Jan 19 '22 at 09:35
  • accepting the answer so that you get the bounty. Thank you for the diagnostic, and let's hope a solution emerges. – seinecle Jan 21 '22 at 13:01