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.

1 Like

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
        )
        ...

Hi, I have encountered the same issue when using cache_resource. Have you managed to solve it? Thank you.

Does the issue persist if you upgrade to streamlit==1.20.0 and restart the app? The latest version fixed a regression related to the /_stcore/ endpoint, and I’m not sure if that’s related:

I haven’t upgraded streamlit and the code is intact, but the error message just disappears since 2023-04-06.

Hi all,
I am getting the same error. It does not look like it is affecting the functionality though. My app is deployed as a private app on the Streamlit Community Cloud and I don’t get this error locally. I have annonymised only a few bits in the code below.

  • I am using Streamlit 1.20.0 and Python 3.10.
  • I don’t know which parts of my code are triggering this

I can provide an high-level example of how I work with session variables

# as soon as the app starts
if "abc" not in st.session_state:
    st.session_state["abc"] = False
if "my_dict" not in st.session_state:
    st.session_state["my_dict"] = {}

# a helper function
def invert_status(sess_variable):
    """Inverts status of a checkbox
    """
    st.session_state[sess_variable] = not st.session_state[sess_variable]

# UI
param = st.sidebar.checkbox("Text", 
                              value=st.session_state["abc"],
                              on_change=invert_status,
                              args=("abc",),
                              )
# further down...
if my_button:
    st.session_state["my_dict"] = {} # resets any previously populated `my_dict` - possibly not needed
    # do stuff
     st.session_state["my_dict"]["a"] = 1 
     st.session_state["my_dict"]["b"] = 2
     st.bar_chart(st.session_state["my_dict"])

From time to time I am seeing the following errors when I click on “Manage app” in the bottom right hand side corner. They don’t occur with every app refresh. There are a few users of the app.

2023-04-14 08:27:19.949 Uncaught exception GET /_stcore/stream (xx.xx.xx.xx)
HTTPServerRequest(protocol='http', host='xxx.streamlit.app', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='xx.xx.xx.xx')
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 361, 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
AssertionError: session with id 'e077d14f-dc22-4eca-ab18-ef0f2c7ca080' is already connected!

Any insight into why these errors might be showing up would be greately appreciated.

this error occurs with no sufficient information. Sometimes when the app is running, this error would occur

I do not see AssertionError, but I do see these a lot in the Streamlit Cloud log:

2023-04-21 01:41:55.029 Session with id e7cf9d5f-88dd-4a23-a7aa-d2942f96cb97 is already connected! Connecting to a new session.

The log does not contain other messages to go on.

Hi, I am having the same issue. I host the streamlit app on Azure web app service. Streamlit 1.20 python 3.8.
I have a backend the frontend sends requests using ZMQ. When this happens, the frontend and backend will lose connection.

2023-05-17T11:24:17.030783881Z HTTPServerRequest(protocol='http', host='ccsnet.ai', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='169.254.129.1')
2023-05-17T11:24:17.030793881Z Traceback (most recent call last):
2023-05-17T11:24:17.030799481Z   File "/usr/local/lib/python3.8/site-packages/tornado/websocket.py", line 937, in _accept_connection
2023-05-17T11:24:17.030805781Z     open_result = handler.open(*handler.open_args, **handler.open_kwargs)
2023-05-17T11:24:17.030811781Z   File "/usr/local/lib/python3.8/site-packages/streamlit/web/server/browser_websocket_handler.py", line 123, in open
2023-05-17T11:24:17.030818581Z     self._session_id = self._runtime.connect_session(
2023-05-17T11:24:17.030824281Z   File "/usr/local/lib/python3.8/site-packages/streamlit/runtime/runtime.py", line 361, in connect_session
2023-05-17T11:24:17.030830581Z     session_id = self._session_mgr.connect_session(
2023-05-17T11:24:17.030836482Z   File "/usr/local/lib/python3.8/site-packages/streamlit/runtime/websocket_session_manager.py", line 65, in connect_session
2023-05-17T11:24:17.030842182Z     assert (
2023-05-17T11:24:17.030847782Z AssertionError: session with id '7148a44f-9b10-43da-ae22-7ecf0b191683' is already connected!

We are facing the exact same issue. Python 3.10 and streamlit 1.19.0 and

Has anyone found a workaround, or even a hint of what may be the underlying cause?

2023-11-14 23:16:55.865 Uncaught exception GET /_stcore/stream (10.21.166.8)
HTTPServerRequest(protocol='http', host='soroban.internal.gcp.missionlane.com', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='10.21.166.8')
Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/anita-9TtSrW0h-py3.10/lib/python3.10/site-packages/tornado/websocket.py", line 937, in _accept_connection
    open_result = handler.open(*handler.open_args, **handler.open_kwargs)
  File "/root/.cache/pypoetry/virtualenvs/anita-9TtSrW0h-py3.10/lib/python3.10/site-packages/streamlit/web/server/browser_websocket_handler.py", line 123, in open
    self._session_id = self._runtime.connect_session(
  File "/root/.cache/pypoetry/virtualenvs/anita-9TtSrW0h-py3.10/lib/python3.10/site-packages/streamlit/runtime/runtime.py", line 349, in connect_session
    session_id = self._session_mgr.connect_session(
  File "/root/.cache/pypoetry/virtualenvs/anita-9TtSrW0h-py3.10/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
AssertionError: session with id 'f3f89a50-fb85-4f48-8f8c-cb124543e1f9' is already connected!