-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unpredictable Behavior of ui.textarea
with Over a Million Characters
#3410
Comments
Hi @Xtreemrus, Thanks for reporting this issue! It looks like Socket.IO (internally using Engine.IO) has a default maximum frame size of 1,000,000 bytes. When we change it in Line 49 in ddb95e1
to something like core.sio = sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*', json=json,
max_http_buffer_size=10_000_000) your example works. So we need to think about whether to somehow detect an overflow and warn the user about it, or to provide a configuration option. What do you think? |
Hi @falkoschindler, Thank you for your reply. I'm glad that the core issue has been identified. While I'm not a professional developer, it seems the problem consists of two parts:
Possible solutions: The solution for point 1 is less obvious, at least from my perspective. Since nothing is propagated to the backend during overflow, we could potentially add a JS script to each ui.input field where overflow might occur. This script would check text.value.length, and if it exceeds max_http_buffer_size (which could be passed as a constant to JS at site startup), it would trigger an exception on the Python side. Simply setting max_http_buffer_size to a very large number and hoping users won't exceed it seems less ideal, as we wouldn't have visibility into how often this event occurs. In an ideal scenario, it would be great if all input fields where possible had an option to specify the maximum number of characters allowed. If a developer sets an input character count higher than max_http_buffer_size, they would receive a warning during ui.run. This wouldn't be an error, but a caution that it could occur. Additionally, giving developers the ability to call a custom function when buffer overflow happens could help them implement user-friendly messages like "Warning: This field is limited to 1 million characters." These approaches would provide more robust error handling and improve the developer and end-user experience. |
According to the engineio sources, async def _websocket_handler(self, ws):
"""Engine.IO handler for websocket transport."""
async def websocket_wait():
data = await ws.wait()
if data and len(data) > self.server.max_http_buffer_size:
raise ValueError('packet is too large')
return data This exception is silently caught elsewhere. |
How about |
I guess this would allow any client to send arbitrarily large packages to the server, which could exhaust the memory and kill the server.
That's bad. But where could this be? Here is the line emitting the socket message: Line 99 in b4fb23d
Any exception caught in |
Description
Description
When
ui.textarea
contains more than a million characters, it starts to behave unpredictably without any visible warnings.Steps to Reproduce
To demonstrate the issue from different perspectives, I wrote the following code:
When you run this code, it creates a textarea filled with over a million characters, plus three more to make the behavior more evident in different scenarios.
Calculate
button immediately after launching (without interacting with theui.textarea
), everything is calculated correctly, and the console prints the appropriate values.ui.textarea
(e.g., delete the digit1
at the beginning or add a new character), theCalculate
button will no longer calculate the new value oftext_area
correctly. The code executes without errors, and you see the print output, but it shows the wrong number of characters and the first character is also incorrect, as if the connection between the frontend and backend is lost.ui.textarea
. In this case, everything works as expected, the counter decreases, and the first characters are read correctly.Additional Investigation
To see if this is a Quasar issue, I added character counting to their textarea code:
https://codepen.io/Xtreemrus/pen/XWLNPyY?editors=101
JS part:
In this case, working with a million characters is handled correctly.
Impact
A couple of years ago, cases requiring a million characters in a textarea were rare. However, with the development of LLMs, users are inserting increasingly large chunks of information into input fields. One million characters are approximately 250,000 tokens, which is now a feasible amount.
Difficulty
The challenge with this bug is that no visible errors occur, neither on the user side nor the developer side. There are no exceptions thrown, making it hard to find a workaround.
Environment
The text was updated successfully, but these errors were encountered: