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

httpx.ReadTimeout #1759

Closed
Boadzie opened this issue Dec 13, 2022 · 16 comments
Closed

httpx.ReadTimeout #1759

Boadzie opened this issue Dec 13, 2022 · 16 comments
Labels
question Question

Comments

@Boadzie
Copy link

Boadzie commented Dec 13, 2022

httpx.ReadTimeout h2o wave

@Boadzie Boadzie added the bug Bug in code label Dec 13, 2022
@mturoci
Copy link
Collaborator

mturoci commented Dec 13, 2022

Can you add more details? Like when this happens, what's your configuration etc Thanks!

@Boadzie
Copy link
Author

Boadzie commented Dec 13, 2022

I set H2O_WAVE_MAX_REQUEST_SIZE=100m and added a new chart. It showed the UI for a while and then the screen went blank

@mturoci
Copy link
Collaborator

mturoci commented Dec 13, 2022

Can you put up a small example app that I could run and debug myself? This is still quite vague.

Edit: Even the whole stack trace would help.

@mturoci mturoci added question Question and removed bug Bug in code labels Dec 13, 2022
@Boadzie
Copy link
Author

Boadzie commented Dec 14, 2022

Error
Traceback (most recent call last):
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/asyncio/selector_events.py", line 943, in _write_ready
    n = self._sock.send(self._buffer)
BrokenPipeError: [Errno 32] Broken pipe

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 33, in read
    return await self._stream.receive(max_bytes=max_bytes)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1274, in receive
    raise self._protocol.exception
anyio.BrokenResourceError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
    yield
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
    raise exc
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/http11.py", line 112, in handle_async_request
    raise exc
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/http11.py", line 91, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_async/http11.py", line 191, in _receive_event
    data = await self._network_stream.read(
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/backends/asyncio.py", line 30, in read
    with map_exceptions(exc_map):
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ReadError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/h2o_wave/server.py", line 341, in _process
    await self._handle(q)
  File "/home/boadzie/Documents/Dev_Master/Projects/wave_music_and_mental_health/src/./app_grid.py", line 65, in serve
    await q.page.save()
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/h2o_wave/core.py", line 608, in save
    await self.site._save(self.url, p)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/h2o_wave/core.py", line 808, in _save
    res = await self._http.patch(_rebase(_config.hub_address, url), content=patch)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1922, in patch
    return await self.request(
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/boadzie/.pyenv/versions/3.10.0/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError

Loading...

@Boadzie
Copy link
Author

Boadzie commented Dec 14, 2022

This is the code

from h2o_wave import Q, ui, main, app
import pandas as pd
from siuba import *
from siuba.siu import call
from charts import show_table, streaming_service, fav_age_effect, fav_depression, fav_insomnia


# read the data anc cover
music = pd.read_csv("../music_mental_survey_clean.csv")
music = music >> select(~_["Unnamed: 0"])  # remove unwanted column


@app("/")
async def serve(q: Q):
    q.page["meta"] = ui.meta_card(
        box="",
        themes=[
            ui.theme(
                name="cool7",
                primary="#ffffff",
                text="#ffffff",
                card="#111111",
                page="#ffffff",
            )
        ],
        theme="cool7",
    )
    q.page["header"] = ui.header_card(
        box=("1 1 10 1"),
        icon="HealthRefresh",
        color="card",
        title="Music's effect on Mental Health",
        subtitle="Can music impact mental health? Let's find out",
    )
    q.page["table"] = ui.form_card(
        box=("1 2 3 5"),
        title="Music and Mental Condition Dataset",
        items=[await show_table(df=music)],
    )

    q.page["streaming_service"] = ui.frame_card(
        box=("4 2 3 5"),
        title="Most popular streaming service",
        content=await streaming_service(df=music),
    )

    q.page["fav_depression"] = ui.frame_card(
        box=("7 2 4 5"),
        title="",
        content=await fav_depression(df=music),
    )

    q.page["fav_age_effect"] = ui.frame_card(
        box=("1 7 5 5"),
        title="",
        content=await fav_age_effect(df=music),
    )

    q.page["fav_insomnia"] = ui.frame_card(
        box=("6 7 5 5"),
        title="",
        content=await fav_insomnia(df=music),
    )

    await q.page.save()

@mturoci
Copy link
Collaborator

mturoci commented Dec 14, 2022

Thanks @Boadzie, this is helpful.

I set H2O_WAVE_MAX_REQUEST_SIZE=100m

I think there is a typo, should be 100M instead of 100m. Could you please try that one? (This assumes the data is <= 100Mb).

re stacktrace: I was working on this yesterday and figured this is a bug in the underlying HTTP lib we use under the hood. Once this PR is merged, I will be able to properly handle the response and display the warning about misconfiguration.

@Boadzie
Copy link
Author

Boadzie commented Dec 14, 2022

Ok thanks for the reply

@Boadzie
Copy link
Author

Boadzie commented Dec 14, 2022

Unfortunately the error persist.

@mturoci
Copy link
Collaborator

mturoci commented Dec 14, 2022

Can you please add music_mental_survey_clean.csv here so that I could try it out?

@Boadzie
Copy link
Author

Boadzie commented Dec 14, 2022

sure
music_mental_survey_clean.csv

@mturoci
Copy link
Collaborator

mturoci commented Dec 15, 2022

Okay, so the CSV is very small ~ 150kb, which is not a problem.

I tried this and works:

from h2o_wave import Q, ui, main, app
import pandas as pd


# read the data anc cover
music = pd.read_csv("music_mental_survey_clean.csv")


@app("/")
async def serve(q: Q):
    q.page["header"] = ui.header_card(
        box=("1 1 10 1"),
        icon="HealthRefresh",
        color="card",
        title="Music's effect on Mental Health",
        subtitle="Can music impact mental health? Let's find out",
    )

    q.page['data'] = ui.markup_card(box='2 2 4 4', title='aa', content=music.to_html())

    await q.page.save()

Can you show me the code for from charts import show_table, streaming_service, fav_age_effect, fav_depression, fav_insomnia these functions? I guess you are using some kind of 3rd party lib that is embedding its own JS which is super big.

@Boadzie
Copy link
Author

Boadzie commented Dec 15, 2022

Yea sure

from h2o_wave import Q, ui
from siuba import *
from siuba.siu import call
import plotly.express as px
import plotly.io as pio
from plotly import graph_objects as go

pio.templates.default = "plotly_dark"


def update_chart(fig):

    return fig.update(
        layout=go.Layout(margin=dict(t=40, r=0, b=40, l=0), legend=dict(yanchor="top", y=0.95, xanchor="left", x=0.01))
    )


# show table of data
async def show_table(df):
    return ui.table(
        name="table",
        height="410px",
        # Add pagination attribute to make your table paginated.
        pagination=ui.table_pagination(total_rows=100, rows_per_page=5),
        events=["page_change"],
        columns=[ui.table_column(name=x, label=x) for x in df.columns.tolist()],
        rows=[ui.table_row(name=str(i), cells=list(map(str, df.values.tolist()[i]))) for i in df.index[0:100]],
    )


async def age_hist(df):
    fig = df >> call(px.histogram, x="age", data_frame=_, labels={"age": "Age"})
    update_chart(fig)
    html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs=True)
    return html


async def streaming_service(df):
    fig = df >> call(
        px.histogram,
        x="primary_streaming_service",
        data_frame=_,
        labels={"primary_streaming_service": "Primary Streaming Service"},
    )
    fig.update_xaxes(categoryorder="total descending")
    update_chart(fig)
    html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs=True)
    return html


async def fav_age_effect(df):
    fig = df >> call(
        px.histogram,
        x="fav_genre",
        y="age",
        color="music_effects",
        data_frame=_,
        text_auto=True,
        histfunc="avg",
        barmode="group",
        title="Music Effect on Listeners - Age",
        labels={"fav_genre": "Fav Genre", "age": "Age"},
    )

    update_chart(fig)
    html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs=True)
    return html


async def fav_depression(df):
    fig = df >> call(
        px.histogram,
        x="fav_genre",
        y="depression",
        color="music_effects",
        data_frame=_,
        text_auto=True,
        histfunc="avg",
        barmode="group",
        title="Music Effect on Listeners - Depression",
        labels={"fav_genre": "Fav Genre", "depression": "Depression"},
    )

    fig.update_yaxes(title="Depression", range=[0, 10])
    update_chart(fig)
    html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs=True)
    return html


async def fav_insomnia(df):
    fig = df >> call(
        px.histogram,
        y="insomnia",
        x="fav_genre",
        color="music_effects",
        data_frame=_,
        text_auto=True,
        histfunc="avg",
        barmode="group",
        title="Music Effect on Listeners - Insomnia",
        labels={"fav_genre": "Fav Genre", "insomnia": "Insomnia"},
    )

    fig.update_yaxes(title="Insomnia", range=[0, 10])
    update_chart(fig)
    html = pio.to_html(fig, config=None, auto_play=True, include_plotlyjs=True)
    return html

@mturoci
Copy link
Collaborator

mturoci commented Dec 15, 2022

Ah okay, the problem is you are pushing the same plotlyjs 5 times (include_plotlyjs=True). Try replacing it with include_plotlyjs='cdn' instead so that the JS won't be embedded within the HTML you are sending.

@Boadzie
Copy link
Author

Boadzie commented Dec 15, 2022

That worked thanks so much!.
Screenshot from 2022-12-15 18-35-53

@mturoci
Copy link
Collaborator

mturoci commented Dec 16, 2022

Glad it worked! Would you mind sharing your app in #1632 once finished?

@mturoci mturoci closed this as completed Dec 16, 2022
@Boadzie
Copy link
Author

Boadzie commented Dec 16, 2022

sure

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

No branches or pull requests

2 participants