> the size of the _putters list is constrained by per-process open file
limits

there is no mechanism to restrict this inherent in the Queue class, it
would be up to the caller to use the class with that restriction

> every _putter represents a socket

no, their design for the Queue is for it to be used by async callers
(coroutines) so there would never be more than 1 entry in the getters
and/or putters.

In the specific use case modified by this patch, the
WebSocketClientConnection class is updated to use the Queue class and,
from its on_message method, return the future object representing the
item put into the Queue. If the Queue has room for the object, its
future object is the 'gen._null_future' object which is always completed
(and whose result it None, but that doesn't matter). If the Queue
doesn't have room, it returns a real future object that won't be
completed until something calls the Queue's get() to take it off the
putters deque.

The caller of WebSocketClientConnection.on_message() is thus responsible
for performing the queue throttling by using the returned future object.
In this case, that caller is WebSocketProtocol13._handle_message(),
which returns the future provided by the call to on_message. The caller
of _handle_message() is WebSocketProtocol13._on_frame_data(), that sets
its local var handled_future to the future returned from the Queue. It
then adds a callback to be called when the future is done, to call
self._receive_frame(); in previous behavior, there was no future object
returned from on_message (and thus _handle_message also returned None)
so _on_frame_data() immediately called self._receive_frame(), which is
what could lead to unthrottled filling of the queue.

Now that _on_frame_data() does get a future object and defers
self._receive_frame() to execution only after the current message
waiting in the Queue._putters deque has been removed, the Queue should
never have more than a single message waiting in its putters.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1903733

Title:
  Out of memory issue for websocket client

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-tornado/+bug/1903733/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to