magfest-archive / mivs

MAGFest Indie Videogame Showcase
GNU Affero General Public License v3.0
2 stars 2 forks source link

url timeout maybe not working - causing gateway errors #51

Closed binary1230 closed 8 years ago

binary1230 commented 8 years ago

when the user submits a MIVS application in application/studio, uber will try and fetch the URL typed in in order to make sure it's a valid website:

def _is_invalid_url(url):
    try:
        log.debug("_is_invalid_url() is fetching '%s' to check if it's reachable." % url)
        with urlopen(url, timeout=30) as f:
            f.read()
    except:
        return True

We're seeing issues that I THINK are related to pages taking too long to load and causing our system to time out. In theory that timeout=30 is supposed to prevent this, but it doesn't seem to be working (or, this isn't the actual issue).

I suspect the timing is going like this:

1) page is submitted 2) we try and fetch the URL and it takes a while 3) 90 seconds later, our upstream frontend nginx server decides the page has taken too long to respond, times out the connection, and responds to the end user with a '504 Gateway error': 2016/09/06 08:08:55 [error] 18255#18255: *152061 upstream timed out (110: Connection timed out) while reading response header from upstream, client: [ip addr hidden], server: super2017.uber.magfest.org, request: "POST /uber/mivs_applications/studio HTTP/1.1", upstream: "http://127.0.0.1:8282/uber/mivs_applications/studio", host: "super2017.uber.magfest.org", referrer: "https://super2017.uber.magfest.org/uber/mivs_applications/studio" 4) 120 seconds later, the MIVS page finishes loading: 2016-09-06 08:09:25,446 [DEBUG] uber.decorators: mivs.site_sections.mivs_applications.studio loaded in 120.25818 seconds but the response goes nowhere.

Things we can do: 1) investigate if that timeout=30 is really working by testing it more carefully 2) add a @with_timing decorator to _is_invalid_url() so that we can measure how long this is taking to make sure it really works.

binary1230 commented 8 years ago

or also, for the record, going out and fetching the URL on a page submit is kind of an insane thing to do, we could just ... stop doing that :) or do it in a thread or something.