Commit 281fe1fb authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Reland "[COOP] Access reporting. Fix the python server."

This is a reland of 9c96261a
The fix was this synchronization:
```
  with request.server.stash.lock:
```

The server is doing a read and a write to a shared state. Those
operations must not unterleave with other request handlers.

Original change's description:
> [COOP] Access reporting. Fix the python server.
>
> A python server is used has a communication channel in between documents
> from different browsing context group and potentially cross-origin.
>
> There are two methods:
> - one for writing a message.
> - one for reading the message.
>
> I initially supposed we won't need to store more than one message in the
> stash. It turns out there are tests doing two write in a row without any
> read in the middle. It was throwing an exception when this
> happened.
>
> This patch makes the server to maintain a queue of messages instead. It
> doesn't throw errors anymore.
>
> Bug: chromium:1109194
> Change-Id: I25f8dc2c2a032781a4527a0994e94e46f85e12c9
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317865
> Reviewed-by: Pâris Meuleman <pmeuleman@chromium.org>
> Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#791901}

Bug: chromium:1109194
Change-Id: I0abbbd9d0ec3b2d3c7c25b0a182c064523c18bd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2322886Reviewed-by: default avatarPâris Meuleman <pmeuleman@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794972}
parent 6081dfcb
......@@ -9,12 +9,19 @@ def main(request, response):
return b''
uuid = request.GET[b'uuid']
stash = request.server.stash;
with stash.lock:
queue = stash.take(uuid)
if queue is None:
queue = []
if request.method == u'POST':
return request.server.stash.put(uuid, request.body)
else:
body = request.server.stash.take(uuid)
if body is None:
return b'not ready'
if request.method == u'POST':
queue.append(request.body)
ret = b'done'
else:
return body
if len(queue) == 0:
ret = b'not ready'
else:
ret = queue.pop(0)
stash.put(uuid, queue)
return ret;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment