# Community Cloud Error: Tornado websocket assertion error in streamlit runtime

**URL:** <https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087>\
**Category:** Community Cloud\
**Tags:** streamlit-cloud\
**Created:** [February 21, 2023, 5:43pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087 "2023-02-21T17:43:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Storm](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/christian_storm/32/23177_2.png) [@Christian\_Storm](https://discuss.streamlit.io/u/Christian_Storm)\
**Post date:** [February 21, 2023, 5:43pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/1 "2023-02-21T17:43:37Z")

</div>

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?

```auto
AssertionError: session with id '065c6898-3658-4975-a924-881bc799b0e2' is already connected!

```

```auto
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')

```

```auto
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

```

---

<div class="post-metadata">

**Author:** ![ferdy](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/ferdy/32/29957_2.png) [@ferdy](https://discuss.streamlit.io/u/ferdy)\
**Post date:** [February 22, 2023, 9:57am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/2 "2023-02-22T09:57:46Z")

</div>

There exists a [guide](https://discuss.streamlit.io/t/using-streamlit-how-to-post-a-question-in-the-streamlit-forum/30960) detailing the steps to resolve a problem.

---

<div class="post-metadata">

**Author:** ![donewiththedollar](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/donewiththedollar/32/23719_2.png) [@donewiththedollar](https://discuss.streamlit.io/u/donewiththedollar)\
**Post date:** [March 5, 2023, 4:14pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/3 "2023-03-05T16:14:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![donewiththedollar](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/donewiththedollar/32/23719_2.png) [@donewiththedollar](https://discuss.streamlit.io/u/donewiththedollar)\
**Post date:** [March 5, 2023, 4:15pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/4 "2023-03-05T16:15:18Z")

</div>

Are you using

@st.cache\_data by chance?

---

<div class="post-metadata">

**Author:** ![Franky1](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/franky1/32/6509_2.png) [@Franky1](https://discuss.streamlit.io/u/Franky1)\
**Post date:** [March 6, 2023, 9:04am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/5 "2023-03-06T09:04:15Z")

</div>

> [@donewiththedollar](#):
>
> This is not by any means a guide detailing the steps to resolve the problem this user is having.

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?

---

<div class="post-metadata">

**Author:** ![Shiina](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shiina/32/22041_2.png) [@Shiina](https://discuss.streamlit.io/u/Shiina)\
**Post date:** [March 10, 2023, 1:57am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/6 "2023-03-10T01:57:22Z")

</div>

I have the same issue from the past week. I have no idea how to reproduce the error, but my code is [here](https://github.com/Shiina18/ydk2decklist) 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.

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![chaosrun](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/chaosrun/32/24684_2.png) [@chaosrun](https://discuss.streamlit.io/u/chaosrun)\
**Post date:** [March 29, 2023, 8:20am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/7 "2023-03-29T08:20:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![snehankekre](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/snehankekre/32/6504_2.png) [@snehankekre](https://discuss.streamlit.io/u/snehankekre)\
**Post date:** [March 29, 2023, 10:25am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/8 "2023-03-29T10:25:13Z")

</div>

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:

> <https://github.com/streamlit/streamlit/pull/6210>
>
> \## 📚 Context
> 
> \#5534 caused a regression where we forgot to update the \`/messag…e\` endpoint (used to fetch
> cached forward msgs from the server when the client's cache is out of sync) to use the new
> \`/\_stcore/message\` endpoint.
> 
> Thankfully, this issue only comes up occasionally since
> \* A \`ForwardMsg\` has to be reasonably large before we decide that it's worth caching to begin with
> \* The client and server normally have \`ForwardMsgCache\`s that are in sync
>    
> This PR makes the trivial fix to correct the endpoint name and also adds e2e tests for fetching
> messages from the server's \`FowardMsgCache\`.
> 
> \## 🧪 Testing Done
> 
> \- \[x\] Added/Updated e2e tests

---

<div class="post-metadata">

**Author:** ![Shiina](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shiina/32/22041_2.png) [@Shiina](https://discuss.streamlit.io/u/Shiina)\
**Post date:** [April 10, 2023, 7:27am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/9 "2023-04-10T07:27:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bogdan](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/bogdan/32/25362_2.png) [@bogdan](https://discuss.streamlit.io/u/bogdan)\
**Post date:** [April 14, 2023, 2:16pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/10 "2023-04-14T14:16:31Z")

</div>

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

```auto
# 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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![dylanxia2017](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/dylanxia2017/32/25440_2.png) [@dylanxia2017](https://discuss.streamlit.io/u/dylanxia2017)\
**Post date:** [April 20, 2023, 9:43am UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/11 "2023-04-20T09:43:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dclin](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/dclin/32/22279_2.png) [@dclin](https://discuss.streamlit.io/u/dclin)\
**Post date:** [April 21, 2023, 5:28pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/12 "2023-04-21T17:28:45Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Gege\_Wen](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/gege_wen/32/26721_2.png) [@Gege\_Wen](https://discuss.streamlit.io/u/Gege_Wen)\
**Post date:** [May 17, 2023, 5:14pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/13 "2023-05-17T17:14:31Z")

</div>

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.

```auto
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!

```

---

<div class="post-metadata">

**Author:** ![David\_Fernando\_Salaz](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/david_fernando_salaz/32/31834_2.png) [@David\_Fernando\_Salaz](https://discuss.streamlit.io/u/David_Fernando_Salaz)\
**Post date:** [November 16, 2023, 4:29pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/14 "2023-11-16T16:29:17Z")

</div>

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?

```auto
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!

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [November 15, 2024, 4:29pm UTC](https://discuss.streamlit.io/t/community-cloud-error-tornado-websocket-assertion-error-in-streamlit-runtime/38087/15 "2024-11-15T16:29:25Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
