HAProxy community

502 Bad Gateway The server returned an invalid or incomplete response

Hello, I have a simple backend:

backend lms_be
option httpchk HEAD / HTTP/1.1\r\nHost:\ lms.FQDN
option accept-invalid-http-response
server lms_be1 10.11.106:80 check

when my client do a post request:

POST /bccr/upload/IsApiFilter/UploadExt.dll??508&template8.asp HTTP/1.1
content-length: 1950
pragma: no-cache
cache-control: no-cache
upgrade-insecure-requests: 1
origin: http://lms.FQDN
content-type: multipart/form-data; boundary=----WebKitFormBoundarysEiqnYXKJIEDKHwC
user-agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
referer: http://lms.FQDN/bccr/asp/fun/test.asp?idresource=66
accept-encoding: gzip, deflate
accept-language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7
cookie: xxxxxxxxxxxxxxxxxxxxxxxx
host: lms.FQDN
x-forwarded-for: 192.168.92.48
FORM DATA

the server (IIS 6) reply with the correct output:

<html>
<head>
.....
</body>
</html>

but the client receive:

HTTP/1.1 502 Bad Gateway
content-length: 107
cache-control: no-cache
content-type: text/html
connection: close
<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>

the haproxy log:

Oct  8 16:33:28 localhost haproxy[2498008]: 192.168.92.48:46999 [08/Oct/2020:16:33:28.495] http-https lms_be/lms_be1 10.1.1.106 0/0/0/-1/11 502 214 - \- PH-- 2/2/0/0/0 0/0 "POST /bccr/upload/IsApiFilter/UploadExt.dll??525&template
8.asp HTTP/1.1"

the strace of the haproxy process:

2495551 recvfrom(66, "<html>\r\n<head>...</html>", 16320, 0, NULL, NULL) = 2615
2495551 recvfrom(66, "", 16320, 0, NULL, NULL) = 0
2495551 sendto(65, "HTTP/1.1 502 Bad Gateway\r\ncontent-length: 107\r\ncache-control: no-cache\r\ncontent-type: text/html\r\nconnection: close\r\n\r\n<html><body><h1>502 Bad Gateway</h1>\nThe server returned an invalid or incomplete response.\n</body></html>\n", 225, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 225

haproxy 2.2.4

Issue a show errors on the admin socket and provide the output:

below the error:

[08/Oct/2020:16:42:54.054] backend lms_be (#113): invalid response
frontend http-https (#3), server lms_be1 (#1), event #0, src 192.168.92.48:47156
buffer starts at 0 (including 0 out), 13769 free,
len 2615, wraps at 16336, error at position 0
H1 connection flags 0x00000000, H1 stream flags 0x0000409c
H1 msg state MSG_RPBEFORE(8), H1 msg flags 0x00001404
H1 chunk len 0 bytes, H1 body len 0 bytes :

  00000  <html>\r\n
  00008  <head>\r\n
  00016  <title>Esystem - Nuovo messaggio</title>\r\n
  00058  <meta name="Credits" content="Metodologia: XXXXXXXXXX">\r\n
  00123  <meta name="Credits" content="Sistemistica: XXXXXXXXXX">\r\n
  00187  <meta name="Credits" content="Programmazione: XXXXXXXXXX">\r\n
  00252  <meta name="Credits" content="Grafica: XXXXXXXXXXX">\r\n
  00312  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1
  00382+ ">\r\n
  00386  </head>\r\n
  00395  <!--\r\n
  00401    I valori "##" vengono sostituiti dall'estensione ISAPI con:\r\n
  00464    Introduzione: perch\xE9 \xE8 importante parlare di rischi e incident
  00528+ i nei luoghi di lavoro  resourceName\r\n
  00566     fileName\r\n
  00579    A0 resourceCode\r\n
  00598    1 resourceSchema\r\n
  00618    1.0 resourceVersion \r\n
  00642    1c resourceScore\r\n
  00662    CMI=HACP resourceParameter\r\n
  00692     resourceLeft\r\n
  00709     resourceTop\r\n
  00725     resourceWidth\r\n
  00743     resourceHeight\r\n
  00762    /resources/esystemresources/Errore_umano/UD1/index_lms.html resource
  00832+ Url\r\n
  00837    88 resourceTipology\r\n
  00860    ##attachmentsId attachmentsId\r\n
  00893    ##rPolicies rPolicies\r\n
  00918    \r\n
  00922    \r\n
  00926    Nota:\r\n
  00935    - La dll deve essere presente nella directory "scripts" nella base d
  01005+ el sito.\r\n
  01015  -->  \r\n
  01022  <body marginheight=14 marginwidth=10 text="#000000" link="#0000df" vli
  01092+ nk="#a8469e" alink="#de0000">\r\n
  01123  \r\n
  01125  <font face="tahoma,arial,helvetica,sans serif" size=2>\r\n
  01181  Attendere il completamento del caricamento...\r\n
  01228  </font>\r\n
  01237  \t<form action="" method="POST" name="hiddenForm">\r\n
  01288  \t\t<input type="hidden" name="attachmentsid" value="526">\r\n
  01346  \t\t<input type="hidden" name="resourceurl" value="/resources/esystemr
  01414+ esources/Errore_umano/UD1/index_lms.html">\r\n
  01458  \t\t<input type="hidden" name="rpolicies" value="24,30">\r\n
  01514  \t\t<input type="hidden" name="resourceName" value="Introduzione: perc
  01582+ h\xE9 \xE8 importante parlare di rischi e incidenti nei luoghi di lavo
  01646+ ro">\r\n
  01652  \t\t<input type="hidden" name="filename" value="">\r\n
  01702  \t\t<input type="hidden" name="resourceCode" value="A0">\r\n
  01758  \t\t<input type="hidden" name="resourceSchema" value="1">\r\n
  01815  \t\t<input type="hidden" name="resourceVersion" value="1.0">\r\n
  01875  \t\t<input type="hidden" name="resourceScore" value="0">\r\n
  01931  \t\t<input type="hidden" name="resourceParameter" value="CMI=HACP">\r
  01997+ \n
  01998  \t\t<input type="hidden" name="resourceData" value="Vendor">\r\n
  02058  \t\t<input type="hidden" name="resourceLeft" value="">\r\n
  02112  \t\t<input type="hidden" name="resourceTop" value="">\r\n
  02165  \t\t<input type="hidden" name="resourceWidth" value="">\r\n
  02220  \t\t<input type="hidden" name="resourceHeight" value="">\r\n
  02276  \t\t<input type="hidden" name="resourceTipology" value="88">\r\n
  02336  \t\t<input type="hidden" name="h_idresource" value="66">\r\n
  02392  \t</form>\r\n
  02402  \r\n
  02404  \t<script language="Javascript">\r\n
  02437  \t\t// esegue automaticamente il submit del form...\r\n
  02488  \t\tdocument.hiddenForm.action =  '../../asp/fun/004100_050.asp'\r\n
  02552  \t\tdocument.hiddenForm.submit();\r\n
  02585  \t</script>\r\n
  02597  \r\n
  02599  </body>\r\n
  02608  </html>

That’s not a valid response. There is not HTTP header at all.

what a fool, I didn’t pay attention to the headers! :sleeping: meanwhile I investigate, I do not mark the problem as solved just to understand why the backend sends me that answer.

thnx a lot.

1 Like

The problem is in a DLL IsApiFilter, using the browser directly it works I guess because it doesn’t respect the standards :slight_smile:

thanx again.