When a DNS response is only partially received over TCP, the session's
I/O handler reads the available data with applet_getblk() and waits for
more. When nothing new is available, the requested length is zero, and
applet_getblk() never reports the shutdown in this case since
applet_may_get() only checks it when more data than available is
requested. If the server closes after sending part of a response, the
session then waits for data that will never come, and queries assigned
to it are lost until it times out, about 20s later.
Let's check for the shutdown when the message is incomplete: the rest
cannot come anymore. This was brought in 3.3 by commit
217da087f
("MEDIUM: dns: Update the dns_session applet to use its own buffers").
It must be backported to 3.3.
if (applet_input_data(appctx) + ds->rx_msg.offset < ds->rx_msg.len) {
/* message only partially available */
+ /* the rest will never come once the server has shut */
+ if (se_fl_test(appctx->sedesc, SE_FL_SHW))
+ goto error;
+
/* read available data */
ret = applet_getblk(appctx, ds->rx_msg.area + ds->rx_msg.offset, applet_input_data(appctx), 0);
if (ret <= 0) {