-
Notifications
You must be signed in to change notification settings - Fork 378
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
fix: Wrap weasyprint to catch exceptions #6728
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9d587f
fix: Wrap weasyprint to catch exceptions (#6324)
pselkirk 353faaa
test: Restore socket function after test
pselkirk 5902168
test: Use mock instead of monkeying with sockets
pselkirk 26cc393
refactor: Log the error
pselkirk 73471ff
fix: Don't catch non-Exception interruptions
pselkirk 3421ea4
Merge branch 'main' into fix-6324
rjsparks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,6 @@ | |
from django import forms | ||
from django.contrib.staticfiles import finders | ||
|
||
from weasyprint.urls import URLFetchingError | ||
|
||
import debug # pyflakes:ignore | ||
|
||
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType, | ||
|
@@ -977,14 +975,8 @@ def document_pdfized(request, name, rev=None, ext=None): | |
|
||
try: | ||
pdf = doc.pdfized() | ||
except URLFetchingError: | ||
# retry once, then give up | ||
try: | ||
pdf = doc.pdfized() | ||
except URLFetchingError as exception: | ||
return render(request, "doc/weasyprint_failed.html", | ||
dict(error=f'{type(exception).__name__}: {exception}'), | ||
status=504) | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be |
||
return render(request, "doc/weasyprint_failed.html") | ||
if pdf: | ||
return HttpResponse(pdf,content_type='application/pdf') | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{# Copyright The IETF Trust 2023, All Rights Reserved #} | ||
{% extends "base.html" %} | ||
{% load origin %} | ||
{% block title %}Network error while rendering PDF{% endblock %} | ||
{% block title %}Error while rendering PDF{% endblock %} | ||
{% block content %} | ||
{% origin %} | ||
<h1>Network error while rendering PDF</h1> | ||
<h1>Error while rendering PDF</h1> | ||
<p> | ||
A network error was encountered while trying to render your document as PDF. | ||
An error was encountered while trying to render your document as PDF. | ||
In case this was a temporary error, you may want to try again in a | ||
little while. | ||
</p> | ||
<p> | ||
We have retried the operation, and it failed again. You may want to wait a bit, and try again. | ||
</p> | ||
<p> | ||
The error was: <code>{{ error }}</code> | ||
A failure report with details about what happened has been sent to the | ||
server administrators. | ||
</p> | ||
{% endblock %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when this fails, it's after a fairly long timeout - I wonder if two timeouts will take us past the cloudflare timeout window?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a log to indicate how often a retry occurs? (Assuming that general failures are also logged, this would let us evaluate whether it's worth trying a second time)
Longer term, this would be a candidate to make into an async response and defer to celery.