StreamClosedError & WebSocketClosedError

Hello everybody. Hope you are all doing great!

I am using streamlit for a couple of weeks now and I am facing a problem that I can’t find any solution. And what is really confusing is the fact that this error happens in some situations, but do not in others with the same code/structure.
When i am running my app, It has a cache_data() function where it checks if the file exists in a S3 bucket, if it does not, it just runs a query, saves a .csv file on S3 and cache the data, so while the server is active, the data is being cached and i don’t need to check the S3 bucket nor run the query.
The .csv file mentioned above has its file size around 30mb.
So when i run my app, this error sometimes pops up on console and it seems to bug my application, taking too long to load (and sometimes it does not load at all):

tornado.iostream.StreamClosedError: Stream is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "xxxxxx/python3.10/site-packages/tornado/websocket.py", line 1090, in wrapper
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
Task exception was never retrieved
future: <Task finished name='Task-1042' coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at xxxxx/python3.10/site-packages/tornado/websocket.py:1086> exception=WebSocketClosedError()>

What I am not understanding is why it happens and why it happens only sometimes, not always.

Any tips on how to solve it? Thank you very much

Hi @Gabriel21

Could you share a code snippet that reproduces the error that you’re seeing, which would be helpful for the community to help identify the error.

Thanks!

Hello, @dataprofessor. I can’t find exactly where the error is coming from. But i am quite sure it’s happening because of the amount of data loaded and rendered, because when i limit the dataset to bring only the first 100 rows, this error never happens (and when i do not limit it, the error pops up sometimes, but sometimes it does not, what makes it even harder to fix).
The code below show how I am loading the data:

if current_date == last_update: 
    data = pd.read_csv(file_name, sep = ';',dtype=cols_type)
else:
    data = wr.athena.read_sql_query(sql = query, database = database,dtype_backend=cols_type) 

This code snippet is wrapped inside a function that has the @st.cache_data() decorator applied to.