Skip to content
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

Internal Error for too large Javascript files included with ui.inline_script #977

Closed
bminixhofer opened this issue Aug 25, 2021 · 4 comments
Labels
bug Bug in code

Comments

@bminixhofer
Copy link

Wave SDK Version, OS

0.17.0, Linux

Actual behavior

Including plotly as inline script via:

import plotly # v2.3.1

# ....

q.page['meta'].script = ui.inline_script(plotly.offline.get_plotlyjs())

fails with

h2o_wave.core.ServiceError: Request failed (code=500): Internal Server Error

Interestingly, I could not reproduce this in a minimal example app using the same script. However, using the unminified version from https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.33.1/plotly.js does the trick.

Expected behavior

I would expect no error to be thrown, or a more informative error message that the size is too large.

Now, since my app has to work offline, I have to create a NamedTemporaryFile with the minified plotly and use q.site.upload (which is also slower than I would expect) to upload the file, then ui.script(...) to include it as a non-inline script.

Steps To Reproduce

  1. wget https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.33.1/plotly.js

app.py

from h2o_wave import Q, main, app, ui

@app("/demo")
async def serve(q: Q):
    q.page['meta'] = ui.meta_card(box='')
    q.page['meta'].script = ui.inline_script(open("plotly.js", "r").read())

    await q.page.save()
$ wave run app
INFO:     Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)
INFO:     Started reloader process [7325] using statreload
INFO:     Started server process [7327]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:33598 - "POST / HTTP/1.1" 200 OK
Unhandled exception
Traceback (most recent call last):
  File "/home/bminixhofer/h2o/wave-minimal/venv/lib/python3.7/site-packages/h2o_wave/server.py", line 305, in _process
    await self._handle(q)
  File "./app.py", line 8, in serve
    await q.page.save()
  File "/home/bminixhofer/h2o/wave-minimal/venv/lib/python3.7/site-packages/h2o_wave/core.py", line 605, in save
    await self.site._save(self.url, p)
  File "/home/bminixhofer/h2o/wave-minimal/venv/lib/python3.7/site-packages/h2o_wave/core.py", line 721, in _save
    raise ServiceError(f'Request failed (code={res.status_code}): {res.text}')
h2o_wave.core.ServiceError: Request failed (code=500): Internal Server Error
@bminixhofer bminixhofer added the bug Bug in code label Aug 25, 2021
@lo5
Copy link
Member

lo5 commented Aug 25, 2021

@bminixhofer - Thank you for the detailed report.

plotly.js is 5.70M, which exceeds the default -max-request-size setting of 5MB, hence the error. Increasing this value should fix the issue.

or a more informative error message that the size is too large.

Agree, this needs fixing.

q.site.upload (which is also slower than I would expect)

This is unexpected. Did you experience this in H2O Cloud, or locally?

@bminixhofer
Copy link
Author

plotly.js is 5.70M, which exceeds the default -max-request-size setting of 5MB

Oh, that makes sense. I still got an error with plotly.min.js in a larger app (Hydrogen Torch) though - I'll check again if I can reproduce it.

This is unexpected. Did you experience this in H2O Cloud, or locally?

I guess I should open a separate issue here - we are dealing with some large files (predictions, model weights etc.) with a couple hundred MB, which we want to make available for download.

I'm running Wave locally, and with the following code:

from h2o_wave import Q, main, app, ui
import time

@app("/demo")
async def serve(q: Q):
    start = time.time()

    (url,) = await q.site.upload(["data.dump"])

    upload_time = time.time() - start
    print(f"upload time: {upload_time}")

    q.page['meta'] = ui.meta_card(box='')
    q.page["meta"].redirect = f"http://localhost:10101/{url}"

    await q.page.save()

I get

$ head -c 100MB < /dev/urandom > data.dump
$ wave run app
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [28044] using statreload
INFO:     Started server process [28046]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:37576 - "POST / HTTP/1.1" 200 OK
upload time: 33.335158348083496

i.e. it takes ~ 33 seconds for a 100MB file to start downloading. Since the file only has to be copied to a location on the same machine, I'd expect the download to start almost immediately, or am I missing something?

@bminixhofer
Copy link
Author

I still got an error with plotly.min.js in a larger app (Hydrogen Torch) though - I'll check again if I can reproduce it.

I can't reproduce this right now so in my opinion this part is solved by 006e282 .

Should I open a separate issue for the upload speed problems?

@bminixhofer
Copy link
Author

I opened a new issue here: #982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in code
Projects
None yet
Development

No branches or pull requests

2 participants