Skip to content

Commit 2c8cc73

Browse files
remote/common: add monkey patch function for maxMessagePayloadSize in WampWebSocketClientFactory.setProtocolOptions
Larger labgrid remote infrastructure setups with a big number of exported resources are limited by the maximum WebSocket payload size of 1M in autobahn [1]: When calling `get_resources()` in this situation, labgrid-client simply hangs. In crossbar's log errors occur: tried to send WebSocket message with size 1068476 exceeding payload limit of 1048576 octets There is no easy way of setting this WebSocket option, since it's set in `ApplicationRunner.run()` [2], which would need to be duplicated into labgrid's source code in its entirety. For an upstream approach, see [3] which was reverted without comment in [4]. So increase the maximum payload size from 1M to 10M by monkey patching maxMessagePayloadSize in WampWebSocketClientFactory.setProtocolOptions(). In oder to be able to actually send these payload sizes, a previous patch already enabled auto fragmentation of outgoing WebSocket messages into multiple WebSocket frames in crossbar's configuration. [1] https://github.com/crossbario/autobahn-python/blob/359f868f9db410586cf01c071220994d8d7f165a/autobahn/asyncio/wamp.py#L223 [2] https://github.com/crossbario/autobahn-python/blob/359f868f9db410586cf01c071220994d8d7f165a/autobahn/asyncio/wamp.py#L90 [3] crossbario/autobahn-python#912 [4] crossbario/autobahn-python#921 Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent a6d1a74 commit 2c8cc73

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
'autobahn',
187187
'autobahn.asyncio',
188188
'autobahn.asyncio.wamp',
189+
'autobahn.asyncio.websocket',
189190
'autobahn.wamp',
190191
'autobahn.wamp.types',
191192
'autobahn.twisted',

labgrid/remote/common.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'ReservationState',
1919
'Reservation',
2020
'enable_tcp_nodelay',
21+
'monkey_patch_max_msg_payload_size_ws_option',
2122
]
2223

2324
TAG_KEY = re.compile(r"[a-z][a-z0-9_]+")
@@ -312,3 +313,36 @@ def enable_tcp_nodelay(session):
312313
"""
313314
s = session._transport.transport.get_extra_info('socket')
314315
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
316+
317+
318+
def monkey_patch_max_msg_payload_size_ws_option():
319+
"""
320+
The default maxMessagePayloadSize in autobahn is 1M. For larger setups with a big number of
321+
exported resources, this becomes the limiting factor.
322+
Increase maxMessagePayloadSize in WampWebSocketClientFactory.setProtocolOptions() by monkey
323+
patching it, so autobahn.asyncio.wamp.ApplicationRunner effectively sets the increased value.
324+
325+
This function must be called before ApplicationRunner is instanciated.
326+
"""
327+
from autobahn.asyncio.websocket import WampWebSocketClientFactory
328+
329+
original_method = WampWebSocketClientFactory.setProtocolOptions
330+
331+
def set_protocol_options(*args, **kwargs):
332+
new_max_message_payload_size = 10485760
333+
334+
# maxMessagePayloadSize given as positional arg
335+
args = list(args)
336+
try:
337+
args[9] = max((args[9], new_max_message_payload_size))
338+
except IndexError:
339+
pass
340+
341+
# maxMessagePayloadSize given as kwarg
342+
kwarg_name = "maxMessagePayloadSize"
343+
if kwarg_name in kwargs and kwargs[kwarg_name] is not None:
344+
kwargs[kwarg_name] = max((kwargs[kwarg_name], new_max_message_payload_size))
345+
346+
return original_method(*args, **kwargs)
347+
348+
WampWebSocketClientFactory.setProtocolOptions = set_protocol_options

0 commit comments

Comments
 (0)