<div dir="ltr"><div>Hi all,</div><div><br></div><div>Not sure if this belongs on the devel mailing list, I thought I would try to post here first.</div><div><br></div><div><br></div><div><b>Summary</b></div><div>The "hash" and "hash ... consistent" upstream directives behave differently when an upstream hostname resolves to multiple IP addresses.<br></div><div><br></div><div><b><br></b></div><div><b>My Use-case:</b></div><div><br></div><div>I am using nginx as a reverse proxy for load balancing inside a docker-compose network.</div><div>In docker-compose, you can setup a service with multiple replicas and with a common hostname. A DNS lookup returns the IP addresses for each replica (e.g. if I have containers "dash_1" and "dash_2", "dash" could resolve to the IP addresses for both).</div><div><br></div><div>The application we are hosting requires sticky sessions. We have implemented this using the "hash ... consistent" upstream directive.</div><div>So an example upstream could look like:</div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(212,212,212)">upstream test_upstream {</span></div><div><span style="color:rgb(212,212,212)">    hash $token</span><span style="color:rgb(106,153,85)"> consistent;</span></div><div><span style="color:rgb(212,212,212)">    server dashboard_test:3838</span><span style="color:rgb(106,153,85)">;</span></div><div><span style="color:rgb(212,212,212)">}</span></div></div></div><div>where "$token" is the unique token for hashing.</div><div>Note that "dashboard_test" can resolve to multiple IP addresses as explained above.</div><div><br></div><div>As I understand it, when nginx starts up it will do a DNS lookup for "dashboard_test" which resolves to multiple IP addresses, effectively resulting in an upstream group with multiple "servers".<br></div><div><br></div><div><br></div><div><b>My Problem:</b><br></div><div><br></div><div>It seems that the "hash" and "hash consistent" directives behave differently.</div><div><br></div><div>I had a quick look at the source (ngx_http_upstream_hash_module.c) and it looks like the "regular" hash method determines an actual IP address from the hash, but the "chash" <b>only determines the entry in the upstream group</b>.</div><div><br></div><div>Empirically, this does seem to be the case. With the "hash" directive nginx always proxies to the same upstream server. With the "hash consistent" directive I get a different upstream server on every request.</div><div><br></div><div>Can anyone comment on whether this is intended behaviour? From my point of view this seems to be a bug. But I can imagine that changing this behaviour might break someone else's use case.</div><div><br></div><div>Kind regards<br></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="color:rgb(102,102,102);font-family:Arial,sans-serif">Ari Croock | Isazi | Software Engineer | BSc (Eng) - Electrical</span></div><div><p style="margin:0px"><font color="#666666"><span style="font-family:Wingdings" lang="EN-ZA"><span style="font-family:Arial,sans-serif">38 Homestead Road, Rivonia, Johannesburg, South Africa, 2128 |</span>(</span><span style="font-family:"Tms Rmn",serif" lang="EN-ZA">:</span><span style="font-family:Arial,sans-serif" lang="EN-ZA"> +27 11 027 6996 </span></font></p><p style="margin:0px"><span style="font-family:Arial,sans-serif" lang="EN-ZA"><font color="#666666"><span style="font-family:Wingdings" lang="EN-ZA">*</span><span style="font-family:"Tms Rmn",serif" lang="EN-ZA">:  </span><span style="font-family:Arial,Helvetica,sans-serif" lang="EN-ZA"><font face="Arial, sans-serif"><a href="mailto:acroock@isazi.ai" target="_blank">acroock@isazi.ai</a> | </font></span><a href="http://www.isazi.ai/" style="font-family:Arial" target="_blank">www.isazi.ai</a><span style="font-family:Arial"> </span></font></span></p></div><div><div><span style="color:rgb(102,102,102);font-family:Arial,sans-serif"><img src="https://drive.google.com/uc?id=1Hqvt6vw0LDuLmQErdARvBc9H_oxfgZzV&export=download" width="200" height="53"></span></div></div></div></div></div></div>