Skip to content

Commit 1a07cbd

Browse files
committed
refactor(handle_source_conversation_deleted): utils.delete_file_object() is non-atomic
1 parent 1dd18ef commit 1a07cbd

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

API2.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,9 @@ state "handle_<event.type>()" as Handler {
176176
Handler --> OK
177177
state "Cache and report success" as SuccessBranch {
178178
OK : 200 OK
179-
MultiStatus : 207 MultiStatus
180-
181179
OK --> UpdateCache
182-
MultiStatus --> UpdateCache
183180
184-
UpdateCache : redis.set(event.id, status, ttl)
181+
UpdateCache : redis.set(event.id, OK, ttl)
185182
UpdateCache --> [*] : return (status, delta)
186183
}
187184

securedrop/journalist_app/api2/events.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,20 @@ def handle_source_conversation_truncated(event: Event, minor: int) -> EventResul
260260
if item.interaction_count <= event.data.upper_bound:
261261
try:
262262
utils.delete_file_object(item)
263-
deleted[item.uuid] = None
264263
except ValueError:
265-
deleted[item.uuid] = item
266-
267-
if any(deleted.values()):
268-
status = EventStatusCode.MultiStatus
269-
else:
270-
status = EventStatusCode.OK
264+
# `utils.delete_file_object()` is non-atomic: it guarantees
265+
# database deletion but not filesystem deletion. The former
266+
# is all we need for consistency with the client, and the
267+
# latter will be caught by monitoring for "disconnected"
268+
# submissions.
269+
pass
270+
finally:
271+
deleted[item.uuid] = None
271272

272273
db.session.refresh(source)
273274
return EventResult(
274275
event_id=event.id,
275-
status=(status, None),
276+
status=(EventStatusCode.OK, None),
276277
sources={source.uuid: source},
277278
items=deleted,
278279
)

securedrop/journalist_app/api2/types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ class EventType(StrEnum):
4444
class EventStatusCode(IntEnum):
4545
Processing = 102
4646
OK = 200
47-
# This event decomposes into multiple actions, some of which succeeded and
48-
# some of which failed. Retries for failures must be submitted in a new event.
49-
MultiStatus = 207
5047
# We already saw and processed this event
5148
AlreadyReported = 208
5249
BadRequest = 400

0 commit comments

Comments
 (0)