Skip to content

Conversation

@amotl
Copy link
Member

@amotl amotl commented May 12, 2022

Problem

There is a test case which validates that the HTTP client croaks appropriately when connecting to non-CrateDB servers.

When connecting to non Crate servers the HttpClient will raise a ConnectionError like this::
>>> http_client = HttpClient(["https://crate.io"])
>>> http_client.server_infos(http_client._get_server())
Traceback (most recent call last):
...
crate.client.exceptions.ProgrammingError: Invalid server response of content-type 'text/html; charset=UTF-8':
...

Within that test, http://crate.io was used as an arbitrary domain to connect to. However, it looks like Fastly now blocks excessive/suspicious requests to that domain, for example when running the test matrix on CI, which invokes quite a number of requests, where their origin might also qualify as "unusual" for some fraud detection algorithms.

By default, the Signal Sciences agent returns a “406” response code when a request is blocked (similar to an HTTP 406 NOT ACCEPTABLE response).

-- https://docs.fastly.com/signalsciences/faq/response-codes/#what-is-a-406-agent-response-code

Traceback from CI

We started to observe those hiccups on behalf of CI jobs for #391 on May 13, 2022 at ~18 o'clock MEST.

Failure in test /home/runner/work/crate-python/crate-python/src/crate/client/doctests/http.txt
Failed doctest test for http.txt
  File "/home/runner/work/crate-python/crate-python/src/crate/client/doctests/http.txt", line 0

----------------------------------------------------------------------
File "/home/runner/work/crate-python/crate-python/src/crate/client/doctests/http.txt", line 187, in http.txt
Failed example:
    http_client.server_infos(http_client._get_server())
Expected:
    Traceback (most recent call last):
    ...
    crate.client.exceptions.ProgrammingError: Invalid server response of content-type 'text/html; charset=UTF-8':
    ...
Got:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/doctest.py", line 1337, in __run
        compileflags, 1), test.globs)
      File "<doctest http.txt[48]>", line 1, in <module>
        http_client.server_infos(http_client._get_server())
      File "/home/runner/work/crate-python/crate-python/src/crate/client/http.py", line 419, in server_infos
        _raise_for_status(response)
      File "/home/runner/work/crate-python/crate-python/src/crate/client/http.py", line 209, in _raise_for_status
        raise ProgrammingError(message)
    crate.client.exceptions.ProgrammingError: 406 Client Error: Not Acceptable

-- https://github.com/crate/crate-python/runs/6409411353#step:6:196

Solution

I thought about using the webserver internal to the testsuite, but just changing the URL to https://httpbin.org/html was an even easier fix. We can come back to the former solution if this ones proves to be brittle as well.

/cc @WalBeh

amotl added 2 commits May 12, 2022 21:29
There is a test case which validates that the HTTP client croaks
appropriately when connecting to non-CrateDB servers.

Within that test, we used http://crate.io to connect to. However, it
looks like Fastly now blocks excessive requests to that domain, for
example when running the test matrix on CI, which invokes quite a number
of requests.

> By default, the Signal Sciences agent returns a “406” response code when a request is blocked (similar to an HTTP 406 NOT ACCEPTABLE response).
>
> -- https://docs.fastly.com/signalsciences/faq/response-codes/#what-is-a-406-agent-response-code
@amotl amotl force-pushed the amo/fix-tests-406 branch from 7bdc7c8 to fc491bd Compare May 12, 2022 19:30
@amotl amotl requested review from mfussenegger and seut May 12, 2022 20:06
@amotl amotl marked this pull request as ready for review May 12, 2022 20:06
@amotl amotl changed the title Fix 406 Client Error: Not Acceptable errors in test suite Fix 406 Client Error: Not Acceptable errors in test suite because new kind of Fastly filtering/blocking May 12, 2022
Copy link
Member

@seut seut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@amotl amotl merged commit e23d651 into master May 13, 2022
@amotl amotl deleted the amo/fix-tests-406 branch May 13, 2022 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants