• Harsh Chouraria's avatar
    Add 15s timeout to GitLab UrlBlocker · b47624c1
    Harsh Chouraria authored
    The URL blocker checks for resolvable addresses of the URLs it receives.
    
    In some cases, bad/stale URLs do not resolve in a finite time, and lead
    to a hang of the call for over the rack/puma timeout levels.
    
    The `Addrinfo.getaddrinfo` call supports passing a timeout since
    Ruby 2.7.0, and this change applies a 15 seconds
    timeout to the operation.
    
    Fix DNS mock helpers
    
    The existing DNS mock helpers do not support receiving just the timeout
    keyword option passed to the getaddrinfo call, leading to the fixture
    failures in the pipeline tests.
    
    Fix misunderstanding of DNS helpers
    
    It looks like the merge request
    https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40490 had already
    added coverage for sending keyword arguments to the getaddrinfo call,
    but only in one stub situation
    
    This change attempts to add the same type of mock to the others
    
    Still unsure if this is entirely right for the tests, but will iterate
    over if it fails again
    
    Add a test forcing DNS timeout
    
    Attempts adding a test to lower the timeout to unreasonable levels
    and expect a DNS lookup failure to occur.
    
    This test may not work as expected on platforms other than Linux due
    to its reliance on the `getaddrinfo_a` call existing.
    
    Also fixed are the DNS helpers (yet again) to only look for the
    timeout params
    
    Stub new parameter `timeout` also in StubRequests spec helper
    
    Fix failing URL blocker timeout specs
    
    Make DNS stubbing less brittle to changes
    
    Skip timeout specs if it's not available
    
    For example, on OSX getaddrinfo_a is not available.
    b47624c1
url_blocker.rb 9.12 KB