<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37611">Hello,</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37611"><br></div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37611" dir="ltr">apologies in advance if this is not the right place to ask questions, but I have some questions that require in-depth understanding of Wildfly and it seems that the users' forum is not the right place to ask them.</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37612">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37613">We have a Wildfly instance installed (wildfly-10.1.0.Final) on standalone mode. We have added a write-timeout="45000" to http-listener &amp; https-listener on production, but we noticed that we get a lot of ClosedChannelException errors:</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37614">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37615">java.nio.channels.ClosedChannelException: null</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37616">at io.undertow.conduits.WriteTimeoutStreamSinkConduit.handleWriteTimeout(WriteTimeoutStreamSinkConduit.java:106)</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37617">at io.undertow.conduits.WriteTimeoutStreamSinkConduit.write(WriteTimeoutStreamSinkConduit.java:122)</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37618">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37619">I would have expected to only see WriteTimeoutException errors, as described here (<a href="https://wildscribe.github.io/WildFly/10.0/subsystem/undertow/server/http-listener/index.html" rel="nofollow" style="padding-right: calc(12px + 0.35ex); border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(55, 120, 199); text-decoration-line: none;" id="yui_3_16_0_ym19_1_1512641275269_37620">WildFly 10.0 Model Reference</a>&nbsp;), which we do, but very occasionally.</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37621">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37622" dir="ltr">By looking at the undertow code (io.undertow.conduits.WriteTimeoutStreamSinkConduit) I noticed that the ClosedChannelException is thrown at the following piece of code:</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37623">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37624">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (expireTimeVar != -1 &amp;&amp; currentTime &gt; expireTimeVar) {</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37625">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IoUtils.safeClose(connection);</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37626">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ClosedChannelException();</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37627">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37628">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37629">We managed to reproduce the problem on the UAT environment, with the following settings:</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37630">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37631">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;http-listener name="default" tcp-keep-alive="false" read-timeout="45000" write-timeout="10000" socket-binding="http" record-request-start-time="true" redirect-socket="https" enable-http2="true"/&gt;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37632">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;https-listener name="https" tcp-keep-alive="false" read-timeout="45000" write-timeout="10000" socket-binding="https" record-request-start-time="true" security-realm="ApplicationRealm" enable-http2="true"/&gt;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37633"><br></div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37633" dir="ltr">and also with the following:</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37633" dir="ltr"><br></div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_49230">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;http-listener name="default" tcp-keep-alive="true" read-timeout="45000" write-timeout="10000" socket-binding="http" record-request-start-time="true" redirect-socket="https" enable-http2="true"/&gt;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" dir="ltr" id="yui_3_16_0_ym19_1_1512641275269_49231">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;https-listener name="https" tcp-keep-alive="true" read-timeout="45000" write-timeout="10000" socket-binding="https" record-request-start-time="true" security-realm="ApplicationRealm" enable-http2="true"/&gt;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37633" dir="ltr"><br></div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37634">We cloned the undertow code and changed the WriteTimeoutStreamSinkConduit.java ourselves (we just added a few debug statements), rebuilt the undertow-core-1.4.0.Final.jar and replaced the one in the UAT environment with our custom version. I noticed the following in the logs</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37635">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37636">[INFO ] 2017-12-05&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-weight: 700; font-style: inherit; font-family: inherit; vertical-align: baseline;" id="yui_3_16_0_ym19_1_1512641275269_37637">12:48:57.240 [default task-6] [pt0_WuRKH4rsd6yPRrXen53Ee2OiPGlNed64iFrI]</span>&nbsp;stdout [?:?] - Updating expire time to: currentTime: 1512470937239 + timeout: 10000</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37638">[INFO ] 2017-12-05&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-weight: 700; font-style: inherit; font-family: inherit; vertical-align: baseline;" id="yui_3_16_0_ym19_1_1512641275269_37639">12:49:11.452 [default task-4] [pt0_WuRKH4rsd6yPRrXen53Ee2OiPGlNed64iFrI]</span>&nbsp;stdout [?:?] - Timeout is set to: 10000</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37640">[INFO ] 2017-12-05 12:49:11.453 [default task-4] [pt0_WuRKH4rsd6yPRrXen53Ee2OiPGlNed64iFrI] stdout [?:?] - currentTime is: 1512470951453 and expireTime is: 1512470947239</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37641">[INFO ] 2017-12-05 12:49:11.454 [default task-4] [pt0_WuRKH4rsd6yPRrXen53Ee2OiPGlNed64iFrI] stdout [?:?] - currentTime &gt; expireTimeVar: true</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37642">[ERROR] 2017-12-05 12:49:11.455 [default task-4] [pt0_WuRKH4rsd6yPRrXen53Ee2OiPGlNed64iFrI] g.c.RestExceptionHandler [RestExceptionHandler.java:24] - Exception Thrown: java.nio.channels.ClosedChannelException</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37643">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37644">If you notice we are talking about two different requests (different thread name) under the same user (same session id) with 14'' delay. I *guess* this exception occurs because the same socket is reused for both requests (for both&nbsp; threads) and thus the expire time applies for all requests over the same socket. But in this case I would expect a WriteTimeoutException, as explained in the docs. So my questions are:</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37645">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37646">a) How exactly does the write-timeout work? I would have thought that each new request resets the timer.</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37647">b) Why don't I get a WriteTimeoutException instead? There are days that we see hundreds of ClosedChannelException but no WriteTimeoutException.</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37648">c) Is there any way to avoid the ClosedChannelException? None of our users has complained yet, but the stack traces clog our log files.</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37649">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" id="yui_3_16_0_ym19_1_1512641275269_37650">Regards</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61); min-height: 8pt;" id="yui_3_16_0_ym19_1_1512641275269_37651">&nbsp;</div><div style="margin-top: 0px; margin-bottom: 0px; border: 0px; font-size: 14px; font-family: Cabin; vertical-align: baseline; color: rgb(61, 61, 61);" dir="ltr" id="yui_3_16_0_ym19_1_1512641275269_37652">Panos</div></div></body></html>