I'm running into file descriptor leakages and found out that you can set net_http_connect_on_start option to true as recommended here.
However when this option is enabled, it's not able to correctly stub out a request with subdomains URLs that fail to resolve DNS lookup. This seems like a bug.
I expect mocked URL's to not actually try to HTTP connect when net_http_connect_on_start is enabled, similar to the behavior when net_http_connect_on_start is disabled.
Actual
WebMock.disable_net_connect!(net_http_connect_on_start: true)
# Stubbing URL with subdomain, results in an error.
stub_request(:get, 'http://api.foobar.com').to_return(body: 'hi')
Net::HTTP.get(URI('http://api.foobar.com'))
# => SocketError: Failed to open TCP connection to api.foobar.com:80 (getaddrinfo: nodename nor servname provided, or not known)
# Stubbing URL with no subdomain, can be stubbed successfully.
stub_request(:get, 'http://foobar.com').to_return(body: 'hi')
Net::HTTP.get(URI('http://foobar.com'))
# => "hi"
# When net_http_connect_on_start defaults to false...
WebMock.disable_net_connect!
# Stubbing URL with subdomain, can be stubbed successfully.
Net::HTTP.get(URI('http://api.foobar.com'))
# => "hi"
Expected
WebMock.disable_net_connect!(net_http_connect_on_start: true)
stub_request(:get, 'http://api.foobar.com').to_return(body: 'hi')
# => "hi"
I'm running into file descriptor leakages and found out that you can set
net_http_connect_on_startoption totrueas recommended here.However when this option is enabled, it's not able to correctly stub out a request with
subdomainsURLs that fail to resolve DNS lookup. This seems like a bug.I expect mocked URL's to not actually try to HTTP
connectwhennet_http_connect_on_startis enabled, similar to the behavior whennet_http_connect_on_startis disabled.Actual
Expected