Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: socket.io upgrade sometimes happen before connect #1471

Conversation

sandangel
Copy link
Contributor

Signed-off-by: San Nguyen vinhsannguyen91@gmail.com

Signed-off-by: San Nguyen <vinhsannguyen91@gmail.com>
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. frontend Pertains to the frontend. labels Oct 23, 2024
@rohanbalkondekar
Copy link

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Race Condition
The handling of the 'upgradeError' and 'connect' events could lead to race conditions or multiple reconnections due to the asynchronous nature of these events. This might result in unexpected behavior or performance issues.

@rohanbalkondekar
Copy link

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

CodiumAI-Agent commented Oct 23, 2024

Title

(Describe updated until commit 6ea3ac0)

fix: socket.io upgrade sometimes happen before connect


User description

Signed-off-by: San Nguyen vinhsannguyen91@gmail.com


PR Type

Bug fix


Description

  • Fixed a bug where the WebSocket upgrade could occur before the connect event, causing issues with user interaction.
  • Simplified the event handling by integrating the 'upgrade' and 'connect' events.
  • Improved error handling by directly referencing socket.io.engine for upgrade errors.

Changes walkthrough 📝

Relevant files
Bug fix
useChatSession.ts
Fix WebSocket upgrade timing issue in useChatSession         

libs/react-client/src/useChatSession.ts

  • Fixed the timing issue where the upgrade to WebSocket could happen
    before the connect event.
  • Removed the separate handling of the 'upgrade' event and integrated it
    with the 'connect' event.
  • Added a check to ensure the WebSocket transport is used before
    invoking the onConnect function.
  • Simplified the error handling for upgrade errors by directly
    referencing socket.io.engine.
  • +12/-16 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @sandangel
    Copy link
    Contributor Author

    Hi, may I ask any update to this PR?

    @dokterbob
    Copy link
    Collaborator

    Hi, may I ask any update to this PR?

    The description of your PR was empty, so it's hard for us to review it.

    Could you please describe in detail:

    1. What specific use case(s) it addresses or, preferably, how we might replicate this issue.
    2. What the expected end result is.
    3. What happens instead?
    4. What reasoning led to the specific proposed solution, including possible alternatives you have considered.

    Lastly, why did you remove the comments there? As this is quite a particular issue, what's the need of not having a direct reference to the context at hand?

    @dokterbob dokterbob added the blocked Awaiting update or feedback from user after initial review/comments. label Nov 6, 2024
    @sandangel
    Copy link
    Contributor Author

    @dokterbob hi, I think I removed those comments because they were not correct.
    These functions are based on socket.io events, but there are race condition when we have listeners nested in other listeners. So the initial implementation was not correct.
    Another issue we have is the socket.io.engine is a different instance when the connection is established, so we should just reference the socket.io.engine directly without assigning variable to it.

    @sandangel
    Copy link
    Contributor Author

    sandangel commented Nov 24, 2024

    Hi, I guess we might just remove the force websocket mode things together. It might not work as intended, hard to test. Any opinion on this?

    @sandangel
    Copy link
    Contributor Author

    Closing. I will open a PR to revert the require websocket that I added before.

    @sandangel sandangel closed this Nov 27, 2024
    @sandangel sandangel deleted the fix/upgrade-sometimes-happen-before-connect branch November 27, 2024 15:23
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    blocked Awaiting update or feedback from user after initial review/comments. frontend Pertains to the frontend. size:S This PR changes 10-29 lines, ignoring generated files.
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    4 participants