Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress Matrix timeout errors in console (fixes #835) #887

Merged
merged 2 commits into from
Apr 2, 2019

Conversation

jerrykan
Copy link
Contributor

Description

The Matrix connector will often receive a timeout error when doing a sync request. The catch-all except would just dump the entire HTML of the timeout response to the console. This output can be quite voluminous and not that useful. By checking for know timeout error codes we can suppress the useless HTML output and just log the occurrence at the info level for those that are interested to know when timeouts occur.

In addition to the standard 504 Gateway Timeout error we also check for 522 Connection timed out and 524 A Timeout Error which are timeout errors specific to Cloudflare. See:

https://support.cloudflare.com/hc/en-us/articles/115003011431/

We check for these Cloudflare errors because the largest Matrix host (matrix.org) is fronted by Cloudflare.

Fixes #835

Status

READY

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

As far as I can tell there are no existing tests covering this part of the codebase, but the changes have been tested against the matrix.org homeserver using Python 3.7.2+ (Debian testing).

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

The Matrix connector will often receive a timeout error when doing a
sync request. The catch-all except would just dump the entire HTML of
the timeout response to the console. This output can be quite voluminous
and not that useful. By checking for know timeout error codes we can
suppress the useless HTML output and just log the occurrence at the info
level for those that are interested to know when timeouts occur.

In addition to the standard `504 Gateway Timeout` error we also check
for `522 Connection timed out` and `524 A Timeout Error` which are
timeout errors specific to Cloudflare. See:

  https://support.cloudflare.com/hc/en-us/articles/115003011431/

We check for these Cloudflare errors because the largest Matrix host
(matrix.org) is fronted by Cloudflare.
@jerrykan
Copy link
Contributor Author

Now that we are handling MatrixRequestError exceptions, it is tempting to remove the catch-all except Exception, but I'm not familiar enough with the codebase to make this call.

@codecov
Copy link

codecov bot commented Mar 30, 2019

Codecov Report

Merging #887 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #887   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          34     34           
  Lines        2201   2201           
=====================================
  Hits         2201   2201
Impacted Files Coverage Δ
opsdroid/connector/matrix/connector.py 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18847d5...9501075. Read the comment docs.

@FabioRosado
Copy link
Member

The broad exception has been used since the beginning of opsdroid, I believe it was implemented in order to catch any exception that doesn't fit the main one. This is the reason why it was added, I'm not entirely sure if it's something that we need.

Although this is a great catch and it does make sense to add a different catch for the timeout errors, also, like you said it's good to avoid filling up the terminal with the whole html file 👍

@jacobtomlinson
Copy link
Member

There needs to be a broad exception catch somewhere to stop broken skills from killing the whole opsdroid process. However I'm happy to discuss whether it would be more appropriate to have it somewhere else.

@FabioRosado FabioRosado merged commit 0854596 into opsdroid:master Apr 2, 2019
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.

Matrix Connector should not log HTML page contents on a 504
4 participants