Community Cloud Error: Tornado websocket assertion error in streamlit runtime

I’m getting this error on the community cloud but not when I run locally. App still seems to work but the logs are filling up with this message. I rebooted the app and that didn’t help.

Any idea what might be causing this and how to fix?

AssertionError: session with id '065c6898-3658-4975-a924-881bc799b0e2' is already connected!
2023-02-20 14:33:48.589 Uncaught exception GET /_stcore/stream (127.0.0.1)

HTTPServerRequest(protocol='http', host='----', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.10/site-packages/tornado/websocket.py", line 942, in _accept_connection
    open_result = handler.open(*handler.open_args, **handler.open_kwargs)
  File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/web/server/browser_websocket_handler.py", line 123, in open self._session_id = self._runtime.connect_session(
  File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/runtime/runtime.py", line 349, in connect_session session_id = self._session_mgr.connect_session(
  File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/runtime/websocket_session_manager.py", line 66, in connect_session existing_session_id not in self._active_session_info_by_id
1 Like

There exists a guide detailing the steps to resolve a problem.

This is not by any means a guide detailing the steps to resolve the problem this user is having. It’s basically a baseline guide for a beginner. It does not describe in any sort of detail of any kind regarding the issue the user is having above. 0/10 response. Edit: OpenAI could have given a better answer, your answer looks like a copy pasta.

Are you using

@st.cache_data by chance?

No, but this is a subtle hint to please provide sufficient information to reproduce the problem. It has unfortunately become epidemic here in the forum that especially new users only post an error message - and sometimes not even that - and expect help. But how are you supposed to help or reproduce this problem if you don’t even get a sample code or a Github link?

1 Like

I have the same issue from the past week. I have no idea how to reproduce the error, but my code is here and it is hosted on streamlit cloud. It uses cache_resource to cache some dicts, reads the uploaded text file, looks up the content in the dict, and finally outputs the converted file.

I’m using streamlit 1.19.0. The log looks something like below. When a user uploads a file, I will log info with its md5. And it seems that the error only happens when no one is using the service. Though it doesn’t seem to hurt my app now, but the log is hardly readable by the repeated error log, and I’m not sure if there is something wrong.

2023-03-09 13:38:10.037 | __main__ | INFO | [md5] e6d3a8ab17cbfd622dbda195f6ff199b [elapsed] 848.0 ms

2023-03-09 13:38:42.559 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
HTTPServerRequest(protocol='http', host='ydk2decklist.streamlit.app', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.8/site-packages/tornado/websocket.py", line 942, in _accept_connection
    open_result = handler.open(*handler.open_args, **handler.open_kwargs)
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/web/server/browser_websocket_handler.py", line 123, in open
    self._session_id = self._runtime.connect_session(
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/runtime/runtime.py", line 349, in connect_session
    session_id = self._session_mgr.connect_session(
  File "/home/appuser/venv/lib/python3.8/site-packages/streamlit/runtime/websocket_session_manager.py", line 65, in connect_session
    assert (
AssertionError: session with id '8f711ddf-6ad9-448b-b153-dc3c5660dbab' is already connected!

then the similar repeats multiple times

2023-03-09 14:35:38.732 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
AssertionError: session with id 'f30a3ed7-af05-4308-ad6c-b867140c4c99' is already connected!
2023-03-09 14:35:39.697 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:40.212 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:40.695 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:41.212 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:41.684 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:42.142 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
2023-03-09 14:35:42.609 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)

2023-03-09 14:39:16.594 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
AssertionError: session with id '0b3637bc-2473-4d55-a7bf-2dc0db9aec05' is already connected!
2023-03-09 14:39:17.077 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)
...
2023-03-09 14:39:19.033 | tornado.application | ERROR | Uncaught exception GET /_stcore/stream (127.0.0.1)

2023-03-09 14:54:07.185 | __main__ | INFO | [md5] 1104472dea235c7f2120ca0d89136314 [elapsed] 295.2 ms

Related streamlit source code

class WebsocketSessionManager(SessionManager):
    def connect_session(
        self,
        client: SessionClient,
        script_data: ScriptData,
        user_info: Dict[str, Optional[str]],
        existing_session_id: Optional[str] = None,
    ) -> str:
        # assertion error here
        assert (
            existing_session_id not in self._active_session_info_by_id
        ), f"session with id '{existing_session_id}' is already connected!"

        session_info = existing_session_id and self._session_storage.get(
            existing_session_id
        )
        ...