[WIP] Make debugger agent startup faster (#17898)
commit10795da1c065c5349bf78ca4d39cfc7992fe5f7c
authorMarek Habersack <grendel@twistedcode.net>
Mon, 25 Nov 2019 16:52:58 +0000 (25 16:52 +0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 25 Nov 2019 16:52:58 +0000 (25 17:52 +0100)
tree39a06ca7270643ddc67503acb1a6c57de8f3dc43
parentf47b7bbf4f0d1a63accab932ec1c8c5fffb4cd3f
[WIP] Make debugger agent startup faster (#17898)

Mono SDB's debugger agent takes a `host:port` parameter to specify the host and
port on which to listen for debugger connection. `host` is passed, via
`mono_get_address_info`, to the `getaddrinfo(3)` standard library call which
does the job of translating the name to the IP address. However, there's no
special treatment for situations when `host` is already an IP address. In this
case `getaddrinfo` takes a lot of time to perform at least two DNS lookups (if
there's just a single DNS server configured) which will time out as the IP
address in `host` will not be resolved by any of the servers.

`getaddrinfo` takes a "hints" parameter where caller can specify some
information about the `host:port` pair to make the lookup faster/easier.
However, Mono doesn't specify the address family in the `hints` parameter, thus
forcing the slow path of DNS lookups on `getaddrinfo`.

This commit adds a new hint named `MONO_HINT_NUMERIC_HOST` (which maps to
`AI_NUMERICHOST` for `getaddrinfo`) which will allow, if set, `getaddrinfo` to
take a faster route in address discovery. Debugger agent will, in most cases,
get an IP address to instead of host name so we call `mono_get_address_info` up
to 3 times (IPv4, IPv6 and unspecified) in order to make the lookup faster.
mono/mini/debugger-agent.c
mono/utils/networking-posix.c
mono/utils/networking.h