openresty / openresty/lua-nginx-module

Prefer ipv6 addresses on dual stack endpoints

Open
#2,430 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

Hi,

I'm using https://github.com/ledgetech/lua-resty-http for sending HTTP requests during request handling in NGINX. I'm sending a request to an upstream endpoint that resolves to 2 IPs, one ipv4 and one ipv6. However, due to the network topology where this is deployed, ipv4 addresses are not reachable from my instance.

The problem is that randomly some request fail to connect, and it appears that the ones that fail are those using the ipv4 address of the upstream endpoint.

I think the root cause of the issue is this:

https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#tcpsockconnect

If the nameserver returns multiple IP addresses for the host name, this method will pick up one randomly.

Is it possible, and if so how, to make the socket prefer ipv6 IP addresses instead of randomly choosing one? Ideally it should transparently work this way but it has not been the case during my testing.

If this is not possible, is there any suggested way to make two concurrent requests and return whichever resolves first? Or customise the resolver configuration for the socket?

I have implemented a workaround by just completely disabling ipv4 resolution but obviously this is not ideal

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tcpsockconnect behavior linked in the report and trace how dual-stack resolver results are selected for outbound sockets. Define what supported IPv6 preference or resolver configuration should look like, and verify that the documented behavior addresses unreachable IPv4 endpoints without relying on the reported workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.