marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.31k stars 155 forks source link

marimo server becomes unusable when several notebooks are open #1653

Closed akshayka closed 1 week ago

akshayka commented 1 week ago

Describe the bug

On macOS, after opening many notebooks, the marimo server can become unusable — notebooks refuse to open, incorrectly claiming that another browser tab is already connected. I don't run into this issue on Ubuntu.

This could be related to #1622.

The following errors are repeatedly emitted in the console:

ERROR:    Exception in ASGI application                                                                                                              
Traceback (most recent call last):                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send            
    await self.send(data)  # type: ignore[arg-type]                                                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 635, in send                                   
    await self.ensure_open()                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open                            
    raise self.connection_closed_exc()                                                                                                               
websockets.exceptions.ConnectionClosedError: no close frame received or sent                                                                         

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

Traceback (most recent call last):                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send                                          
    await self._send(message)                                                                                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender                                
    await send(message)                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper                         
    await send(message)                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 345, in asgi_send            
    raise ClientDisconnected from exc                                                                                                                
uvicorn.protocols.utils.ClientDisconnected                                                                                                           

During handling of the above exception, another exception occurred:                                                                                  

Traceback (most recent call last):                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi                                                  
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__                                                               
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__                                                                        
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__                                                                   
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__                                                                       
    return await super().__call__(scope, receive, send)                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                                                  
    await self.app(scope, receive, send_wrapper)                                                                                                                                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__                                                            
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__                                                                      
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__                                                                  
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__                                                                
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                
    raise exc                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                
    await app(scope, receive, sender)                                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                             
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                  
    await route.handle(scope, receive, send)                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                               
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                             
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                  
    await route.handle(scope, receive, send)                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                               
    await self.app(scope, receive, send)                                                                                                                                                                      [413/896]
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                                                                                                               
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                                                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                            
    raise exc                                                                                                                                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                            
    await app(scope, receive, sender)                                                                                                                                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 94, in app                                                                                                               
    await func(session)                                                                                                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint                                                                                  
    await WebsocketHandler(                                                                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 386, in start                                                                                              
    await self.future                                                                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 318, in listen_for_messages                                                                                
    await self.websocket.send_text(                                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 188, in send_text                                                                                                     
    await self.send({"type": "websocket.send", "text": data})                                                                                                                                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 100, in send                                                                                                          
    raise WebSocketDisconnect(code=1006)                                                                                                                                                                               
starlette.websockets.WebSocketDisconnect                                                                      
ERROR:    Exception in ASGI application                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi                                                  
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__                                                               
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__                                                                        
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__                                                                   
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__                                                                       
    return await super().__call__(scope, receive, send)                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                                                  
    await self.app(scope, receive, send_wrapper)                                                                                                                                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__                                                            
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__                                                                      
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__                                                                  
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__                                                                
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                
    raise exc                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                
    await app(scope, receive, sender)                                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                             
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                  
    await route.handle(scope, receive, send)                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                               
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                             
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                  
    await route.handle(scope, receive, send)                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                               
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                                                                                   
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                                                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                
    raise exc                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                
    await app(scope, receive, sender)                                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 94, in app                                                                                   
    await func(session)                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint                                                      
    await WebsocketHandler(                                                                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 249, in start                                                                  
    await self.websocket.close(                                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 203, in close                                                                             
    await self.send(                                                                                                                                                                         File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send                                          
    await self._send(message)                                                                                                                                                                File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender                                
    await send(message)                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper                                                              
    await send(message)                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 338, in asgi_send            
    await self.close(code, reason)                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 788, in close                                  
    await self.transfer_data_task                                                                                                                                                          
AttributeError: 'WebSocketProtocol' object has no attribute 'transfer_data_task'                                                                                                           
ERROR:    Exception in ASGI application                             

Environment

{
  "marimo": "0.6.19",
  "OS": "Darwin",
  "OS Version": "22.5.0",
  "Processor": "arm",
  "Python Version": "3.9.19",
  "Binaries": {
    "Browser": "126.0.6478.62",
    "Node": "v21.5.0"
  },
  "Requirements": {
    "click": "8.1.7",
    "importlib-resources": "5.10.2",
    "jedi": "0.19.1",
    "markdown": "3.6",
    "pymdown-extensions": "10.8.1",
    "pygments": "2.18.0",
    "tomlkit": "0.12.5",
    "uvicorn": "0.30.1",
    "starlette": "0.37.2",
    "websockets": "12.0",
    "typing-extensions": "4.12.2",
    "black": "24.4.2"
  }
}

Code to reproduce

  1. Run marimo edit in a directory with several notebooks
  2. Open around 10 notebooks.
akshayka commented 1 week ago

More context, this time with server debug logs.

[D 240619 20:55:10 assets:76] File key provided: ibis_example.py                                                                                                                           
[D 240619 20:55:11 ws:338] Websocket disconnected for session s_prg5ll with exception (<CloseCode.ABNORMAL_CLOSURE: 1006>, None)                                                           
[D 240619 20:55:11 sessions:372] Disconnecting session consumer                                                                                                                            
ERROR:    Exception in ASGI application                                                                                                                                                    
Traceback (most recent call last):                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 963, in transfer_data                                                               
    message = await self.read_message()                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1033, in read_message                                                               
    frame = await self.read_data_frame(max_size=self.max_size)                                                                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1108, in read_data_frame                                                            
    frame = await self.read_frame(max_size)                                                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1165, in read_frame                                                                 
    frame = await Frame.read(                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/framing.py", line 68, in read                                                                          
    data = await reader(2)                                                                                                                                                                 
  File "/opt/homebrew/Cellar/python@3.9/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 721, in readexactly                                        
    raise exceptions.IncompleteReadError(incomplete, n)                                                                                                                                    
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes                                                                                                        

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

Traceback (most recent call last):                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send                                                 
    await self.send(data)  # type: ignore[arg-type]                                                                                                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 647, in send                                                                        
    await self.write_frame(True, opcode, data)                                                                                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1209, in write_frame                                                                
    await self.drain()                                                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1198, in drain                                                                      
    await self.ensure_open()                                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open                                                                 
    raise self.connection_closed_exc()                                                                                                                                                     
websockets.exceptions.ConnectionClosedError: no close frame received or sent                                                                                                               

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

Traceback (most recent call last):                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send                                                                               
    await self._send(message)                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender                                                                     
    await send(message)                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper                                                              
    await send(message)                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 345, in asgi_send                                                 
    raise ClientDisconnected from exc                                                                                                                                                      
uvicorn.protocols.utils.ClientDisconnected                                                                                                                                                 

During handling of the above exception, another exception occurred:                                                                                                                        

Traceback (most recent call last):                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi                                                  
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__                                                               
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__                                                                        
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__                                                                   
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__                                                                       
    return await super().__call__(scope, receive, send)                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                                                  
    await self.app(scope, receive, send_wrapper)                                                                                                                                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__                                                            
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__                                                                      
    await self.app(scope, receive, send)                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__                                                                  
    return await self.app(scope, receive, send)                                                                                                                                            
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__                                                                
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                
    raise exc                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                
    await app(scope, receive, sender)                                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                             
    await self.middleware_stack(scope, receive, send)                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                   
    await route.handle(scope, receive, send)                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                                                                                             
    await self.app(scope, receive, send)                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                           
    await self.middleware_stack(scope, receive, send)                                                                       
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                   
    await route.handle(scope, receive, send)                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                                                                                             
    await self.app(scope, receive, send)                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                    
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                              
    raise exc                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                              
    await app(scope, receive, sender)                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 94, in app                    
    await func(session)                                       
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint                                                                                                                    
    await WebsocketHandler(                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 386, in start                                                                                                                                
    await self.future                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 318, in listen_for_messages                                                                                                                  
    await self.websocket.send_text(                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 188, in send_text                                                                                                                                       
    await self.send({"type": "websocket.send", "text": data})                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 100, in send                                                                                                                                            
    raise WebSocketDisconnect(code=1006)                      
akshayka commented 1 week ago

Many similar failures, with the server accumulating orphaned connections (see end of below list):

[D 240619 20:55:16 ws:239] Existing sessions: {'s_nsgbwl': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d3e400>), 's_p6coxg': Session(connection_state=ConnectionState.OPEN, 
consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d7c310>), 's_uoyzbw': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102dc0940>), 's_nnh9fy': Session(co
nnection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102ddbb50>), 's_pwgnhu': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 
0x102e0cd90>), 's_ayah5b': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x10543c520>), 's_culsus': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.end
points.ws.WebsocketHandler object at 0x102a57790>), 's_clvgt7': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x105496550>), 's_saujr5': Session(connection_state=ConnectionState.O
PEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054cfdc0>), 's_v0q011': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054bf2e0>), 's_s0wxdt': Sessi
on(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1055e4f70>), 's_prg5ll': Session(connection_state=ConnectionState.ORPHANED, consumer=None), 's_y0jq9f': Session(connection_state=Connect
ionState.ORPHANED, consumer=None), 's_yrz89s': Session(connection_state=ConnectionState.ORPHANED, consumer=None)}
akshayka commented 1 week ago

And logs for when a connection is refused. Not sure why there's an open, followed by reconnect, followed by refusal — browser tab wasn't refreshed or re-opened at any point. There's also some marimo code in the traceback.

[D 240619 20:55:21 ws:236] Websocket open request for session with id s_y0jq9f                                                                                                                                                                                                                                                                                                       
[D 240619 20:55:21 ws:239] Existing sessions: {'s_nsgbwl': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d3e400>), 's_p6coxg': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d7c310>), 's_uoyzbw': Session(connection_state=Con
nectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102dc0940>), 's_nnh9fy': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102ddbb50>), 's_pwgnhu': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at
 0x102e0cd90>), 's_ayah5b': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x10543c520>), 's_culsus': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102a57790>), 's_clvgt7': Session(connection_state=ConnectionState.OPEN, consumer=<ma
rimo._server.api.endpoints.ws.WebsocketHandler object at 0x105496550>), 's_saujr5': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054cfdc0>), 's_v0q011': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054bf2e0>), 's_s0wxdt': Ses
sion(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1055e4f70>), 's_prg5ll': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3040>), 's_y0jq9f': Session(connection_state=ConnectionState.ORPHANED, consumer=None), 's_yrz89s': Session(con
nection_state=ConnectionState.ORPHANED, consumer=None), 's_m383mb': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3ca0>)}                                                                                                                                                                               
[D 240619 20:55:21 ws:264] Reconnecting session s_y0jq9f                                                                                                                                                                                                                                                                                                                             
[D 240619 20:55:23 ws:236] Websocket open request for session with id s_yrz89s                                                                                                                                                                                                                                                                                                       
[D 240619 20:55:23 ws:239] Existing sessions: {'s_nsgbwl': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d3e400>), 's_p6coxg': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d7c310>), 's_uoyzbw': Session(connection_state=Con
nectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102dc0940>), 's_nnh9fy': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102ddbb50>), 's_pwgnhu': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at
 0x102e0cd90>), 's_ayah5b': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x10543c520>), 's_culsus': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102a57790>), 's_clvgt7': Session(connection_state=ConnectionState.OPEN, consumer=<ma
rimo._server.api.endpoints.ws.WebsocketHandler object at 0x105496550>), 's_saujr5': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054cfdc0>), 's_v0q011': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054bf2e0>), 's_s0wxdt': Ses
sion(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1055e4f70>), 's_prg5ll': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3040>), 's_y0jq9f': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.W
ebsocketHandler object at 0x105718220>), 's_yrz89s': Session(connection_state=ConnectionState.ORPHANED, consumer=None), 's_m383mb': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3ca0>)}
[D 240619 20:55:23 ws:264] Reconnecting session s_yrz89s                                                                                                                                                              
[D 240619 20:55:23 ws:236] Websocket open request for session with id s_prg5ll                                                                                                                                        
[D 240619 20:55:23 ws:239] Existing sessions: {'s_nsgbwl': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d3e400>), 's_p6coxg': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102d7c310>), 's_uoyzbw': Session(connection_state=Con
nectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102dc0940>), 's_nnh9fy': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102ddbb50>), 's_pwgnhu': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at
 0x102e0cd90>), 's_ayah5b': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x10543c520>), 's_culsus': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x102a57790>), 's_clvgt7': Session(connection_state=ConnectionState.OPEN, consumer=<ma
rimo._server.api.endpoints.ws.WebsocketHandler object at 0x105496550>), 's_saujr5': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054cfdc0>), 's_v0q011': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1054bf2e0>), 's_s0wxdt': Ses
sion(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1055e4f70>), 's_prg5ll': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3040>), 's_y0jq9f': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.W
ebsocketHandler object at 0x105718220>), 's_yrz89s': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x10560ad60>), 's_m383mb': Session(connection_state=ConnectionState.OPEN, consumer=<marimo._server.api.endpoints.ws.WebsocketHandler object at 0x1056f3ca0>)}
[D 240619 20:55:23 ws:245] Refusing connection; a frontend is already connected.                                                                                                                                      
ERROR:    Exception in ASGI application                                                                                                                                                                               
Traceback (most recent call last):                                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send                                                                            
    await self.send(data)  # type: ignore[arg-type]                                                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 635, in send                                                                                                   
    await self.ensure_open()                                                                                                                                                                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open                                                                                            
    raise self.connection_closed_exc()                                                                                                                                                                                
websockets.exceptions.ConnectionClosedError: no close frame received or sent                                                                                                                                          

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

Traceback (most recent call last):                                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send                                                                                                          
    await self._send(message)                                                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender                                                                                                
    await send(message)                                                                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper                                                                                         
    await send(message)                                                                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 345, in asgi_send                                                                            
    raise ClientDisconnected from exc                                                                                                                                                                                 
uvicorn.protocols.utils.ClientDisconnected                                                                                                                                                                            

During handling of the above exception, another exception occurred:                                                                                                                                                   

Traceback (most recent call last):                                                                                                                                                                                    
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi                                                                             
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]                                                                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__                                                                                          
    return await self.app(scope, receive, send)                                                                                                                                                                       
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__                                                                                                   
    await self.middleware_stack(scope, receive, send)                                                                                                                                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__                                                                                              
    await self.app(scope, receive, send)                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__                                                                                                  
    return await super().__call__(scope, receive, send)                                                                                                                                                               
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                                                                             
    await self.app(scope, receive, send_wrapper)                                                                                                                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__                                                                                       
    await self.app(scope, receive, send)                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__                                                                                                 
    await self.app(scope, receive, send)                                                                                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__                                                                                                                                                                                                                                                            
    return await self.app(scope, receive, send)                                                                                                                                                                       
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__                                                                                                                                                                                                                                                          
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                                                                                                                                                          
    raise exc                                                                                                                                                                                                         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                                                          
    await app(scope, receive, sender)                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                                                                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                                                                                  
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                                                                                                                                                          
    raise exc                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                                                          
    await app(scope, receive, sender)                                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 94, in app                                                                                  
    await func(session)                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint                                                                                                                                                                                                                                                
    await WebsocketHandler(                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 386, in start                                                                                                                                                                                                                                                            
    await self.future                                                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 318, in listen_for_messages                                                                                                                                                                                                                                              
    await self.websocket.send_text(                                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 188, in send_text                                                                                                                                                                                                                                                                   
    await self.send({"type": "websocket.send", "text": data})                                                                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 100, in send                                                                                                                                                                                                                                                                        
    raise WebSocketDisconnect(code=1006)                                                                                                                                                  
starlette.websockets.WebSocketDisconnect                                                                                                                                                  
ERROR:    Exception in ASGI application                                                      
Traceback (most recent call last):                                                                                                                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send                                                                                                                                                                                                                                           
    await self.send(data)  # type: ignore[arg-type]                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 635, in send                                                                                                                                                                                                                                                                  
    await self.ensure_open()                                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open                                                                                                                                                                                                                                                           
    raise self.connection_closed_exc()                                                       
websockets.exceptions.ConnectionClosedError: no close frame received or sent                                                                                                              

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

Traceback (most recent call last):                                                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send                                                                                                                                                                                                                                                                         
    await self._send(message)                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender                                                                                                                                                                                                                                                               
    await send(message)                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper                                                                                                                                                                                                                                                        
    await send(message)                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 345, in asgi_send                                                                                                                                                                                                                                           
    raise ClientDisconnected from exc                                                        
uvicorn.protocols.utils.ClientDisconnected                                                   

During handling of the above exception, another exception occurred:                                                                                                                       

Traceback (most recent call last):                                                           
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi                                                                                                                                                                                                                                            
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]                                                                                                                                                                                                                                                                       
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__                                                                                                                                                                                                                                                         
    return await self.app(scope, receive, send)                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__                                                                                                                                                                                                                                                                  
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__                                                                                                                                                                                                                                                             
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__                                                                                                                                                                                                                                                                 
    return await super().__call__(scope, receive, send)                                                                                                                                   
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                                                                                                                                                                                                                                            
    await self.app(scope, receive, send_wrapper)                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__                                                                                                                                                                                                                                                      
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__                                                                                                                                                                                                                                                                
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__                                                                                                                                                                                                                                                            
    return await self.app(scope, receive, send)                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__                                                                                                                                                                                                                                                          
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                              
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                                                                                                                                                          
    raise exc                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                                                          
    await app(scope, receive, sender)                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                                                                                  
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                                                                                                                                                          
    raise exc                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                                                          
    await app(scope, receive, sender)         
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__                                                                                                                                                                                                                                                                       
    await self.middleware_stack(scope, receive, send)                                                                                                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 776, in app                                                                                 
    await route.handle(scope, receive, send)                                                 
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle                                                                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                     
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 96, in app                                                                                  
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)                                                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app                                                                                                                                                                                                                                                          
    raise exc                                                                                
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                                                          
    await app(scope, receive, sender)                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/routing.py", line 94, in app                                                                                  
    await func(session)                                                                      
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint                                                                                                                                                                                                                                                
    await WebsocketHandler(                                                                  
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 386, in start                                                                                                                                                                                                                                                            
    await self.future                                                                        
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 318, in listen_for_messages                                                                                                                                                                                                                                              
    await self.websocket.send_text(                                                          
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 188, in send_text                                                                                                                                                                                                                                                                   
    await self.send({"type": "websocket.send", "text": data})                                                                                                                             
  File "/Users/akshay/envs/playground/lib/python3.9/site-packages/starlette/websockets.py", line 100, in send                                                                                                                                                                                                                                                                        
    raise WebSocketDisconnect(code=1006)
akshayka commented 1 week ago

The WebSocket is being closed before the handshake is completed. Not sure why.

Frontend logs show:

image

Similarly when uvicorn's connection_lost() method is called, it determines that the connection was lost before the handshake was completed.

akshayka commented 1 week ago

image