Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ooniapi/services/ooniprobe/src/ooniprobe/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ class Metrics:
)

TEST_LIST_URLS_COUNT = Gauge("test_list_urls_count", "Size of reported test list")

CLIENT_DISCONNECT = Counter(
"client_upload_disconnect", "Client disconnected while awaiting report"
)
11 changes: 10 additions & 1 deletion ooniapi/services/ooniprobe/src/ooniprobe/routers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ async def receive_measurement(
Metrics.MSMNT_DISCARD_CC_ZZ.inc()
return empty_measurement

data = await request.body()
try:
data = await request.body()
except ClientDisconnect:
log.info(f"Client disconnected mid-upload")
Metrics.CLIENT_DISCONNECT.inc()
return empty_measurement
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should verify how clients behave when we return empty_measurement instead of raising an exception, since this might affect changes in the client behavior.

I would actually suggest we preserve the original behavior by re-rasing the exception

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if we re-raise the exception it pollutes the logs with a Traceback; but if the client has disconnected - how would it receive anything?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah I think for the ClientDisconnect you are right. In the case of the catch-all exception, we ought to though return something that's an error to the client, either a 5xx error (by just re-raising the exception) or a specific 5xx/4xx status code.

except Exception as e:
log.error(f"Uncaught exception {e}")
return empty_measurement
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should return something that indicates that this was not a successful submission; verify what repsonse should be sent. IE, should re-raise as a wrapped HTTPException?


if content_encoding == "zstd":
try:
compressed_len = len(data)
Expand Down
Loading