aicam opened a new issue, #6419:
URL: https://github.com/apache/texera/issues/6419

   ## Bug
   
   In `CoeditorPresenceService.observeUserState()`, the y-websocket awareness 
`"change"` handler reads `coeditorState.user.clientId` without checking that 
`user` exists:
   
   
https://github.com/apache/texera/blob/master/frontend/src/app/workspace/service/workflow-graph/model/coeditor-presence.service.ts#L118-L121
   
   ```ts
   for (const clientId of change.added) {
     const coeditorState = this.getCoeditorStatesMap().get(clientId);
     if (coeditorState && coeditorState.user.clientId !== 
this.getLocalClientId()) this.addCoeditor(coeditorState);
   }
   ```
   
   y-websocket's `Awareness` initializes every client's local state to `{}`, so 
any peer that joins the room before setting its `user` field (or that never 
sets it — e.g. a non-Texera Yjs client, a monitoring script, or a Texera tab 
mid-initialization) delivers a state without `user`, and this handler throws:
   
   ```
   ERROR TypeError: Cannot read properties of undefined (reading 'clientId')
   ```
   
   The `change.updated` branch a few lines below has the same problem 
(`addCoeditor` → `coeditorState.user` at line 154).
   
   Note the *initial-scan* code right above it already guards correctly:
   
   ```ts
   const currentStates = this.getCoeditorStatesArray().filter(
     userState => userState.user && userState.user.clientId && 
userState.user.clientId !== this.getLocalClientId()
   );
   ```
   
   so this is just a missing guard in the change handler.
   
   ## Impact
   
   The error is thrown inside an awareness event handler, so it surfaces as an 
unhandled `ERROR TypeError` in the console every time any such peer joins or 
updates. Depending on what else shares the Yjs event dispatch, it can disrupt 
other awareness observers.
   
   ## Reproduction
   
   1. Open a workflow (shared editing on).
   2. Connect a plain Yjs client to the same room without setting awareness 
user state:
      ```js
      const provider = new WebsocketProvider(url, `${wid}`, new Y.Doc(), { 
WebSocketPolyfill: require("ws") });
      ```
   3. The Texera tab logs `TypeError: Cannot read properties of undefined 
(reading 'clientId')`.
   
   Observed while testing #6240 on a local minikube deployment (crash 
reproduced against the current image; the code is unchanged on master).
   
   ## Suggested fix
   
   Apply the same guard as the initial scan in both the `added` and `updated` 
branches:
   
   ```ts
   if (coeditorState && coeditorState.user && coeditorState.user.clientId !== 
this.getLocalClientId()) ...
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to