jsoncom: gracefully report EMSGSIZE errors

When `jsoncomm` fails because the message is too big it currently
does not indicate just how big the message was. This commit adds
this information so that it's easier for us to determine what to
do about it.

We could also include a pointer to `/proc/sys/net/core/wmem_defaults`
but it seems we want to not require fiddling with that so let's
not do it for now.

See also https://github.com/osbuild/osbuild/pull/1838
This commit is contained in:
Michael Vogt 2024-08-12 14:36:51 +02:00 committed by Achilleas Koutsou
parent f4dc0f3f20
commit 29f926f305
2 changed files with 19 additions and 1 deletions

View file

@ -3,12 +3,15 @@
#
import asyncio
import errno
import os
import pathlib
import tempfile
import unittest
from concurrent import futures
import pytest
from osbuild.util import jsoncomm
@ -216,3 +219,12 @@ class TestUtilJsonComm(unittest.TestCase):
self.assertEqual(ping, pong)
pong, _, _ = a.recv()
self.assertEqual(ping, pong)
def test_send_and_recv_tons_of_data_still_errors(self):
a, _ = jsoncomm.Socket.new_pair()
ping = {"data": "1" * 1_000_000}
with pytest.raises(BufferError) as exc:
a.send(ping)
assert str(exc.value) == "jsoncomm message size 1000012 is too big"
assert exc.value.__cause__.errno == errno.EMSGSIZE