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

feat: JS API reconnect #1149

Merged
merged 7 commits into from
Mar 29, 2023
Merged

feat: JS API reconnect #1149

merged 7 commits into from
Mar 29, 2023

Conversation

mofojed
Copy link
Member

@mofojed mofojed commented Mar 14, 2023

  • Listen for EVENT_DISCONNECT and EVENT_RECONNECT on the connection, and display a "Reconnecting..." message in the console.
  • No longer listen to the HACK_CONNECTION_FAILURE (it's been deprecated).
  • Listen for the SHUTDOWN event and display a message after shutdown.
  • Fixes Support reconnecting to the server #1140
    Testing steps:
  1. Start up server with deephaven-core JS API reconnect changes: JS API should attempt to reconnect to the gRPC server deephaven-core#3502
  2. Use ngrok to start a tunnel to that port, e.g.: ngrok http 10000
  3. Start up Web UI connecting to that tunnel, e.g.: VITE_CORE_API_URL=http://acfc-23-233-0-34.ngrok.io/jsapi npm start
  4. Open the Web UI in Firefox, run some commands to make sure initial connection is fine.
  5. Press Alt and from the File menu, select "Work Offline"
  6. See it transition to a disconnected state. Disconnected message should appear and should not be able to enter new commands
  7. Reconnect by deselecting "Work Offline" option from Step 5
  8. See it transition to connected state. Should be able to run commands and have the results appear.
  9. Kill the server (Ctrl+C). See it transition to a Shutdown state, app unloaded.

- Doesn't work correctly yet
- Not sure how best to test locally
@mofojed mofojed requested a review from mattrunyon March 23, 2023 16:35
@mofojed mofojed self-assigned this Mar 23, 2023
@mofojed mofojed added this to the March 2023 milestone Mar 23, 2023
@mofojed mofojed marked this pull request as ready for review March 23, 2023 16:36
@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #1149 (b72e295) into main (2ac25ae) will increase coverage by 0.03%.
The diff coverage is 27.58%.

@@            Coverage Diff             @@
##             main    #1149      +/-   ##
==========================================
+ Coverage   44.15%   44.19%   +0.03%     
==========================================
  Files         447      448       +1     
  Lines       33267    33310      +43     
  Branches     8356     8364       +8     
==========================================
+ Hits        14688    14720      +32     
- Misses      18530    18541      +11     
  Partials       49       49              
Flag Coverage Δ
unit 44.19% <27.58%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/code-studio/src/main/AppInit.tsx 0.00% <0.00%> (ø)
packages/components/src/modal/InfoModal.tsx 0.00% <0.00%> (ø)
packages/console/src/HeapUsage.tsx 0.00% <0.00%> (ø)
...dashboard-core-plugins/src/panels/ConsolePanel.tsx 46.04% <ø> (ø)
packages/code-studio/src/main/AppMainContainer.tsx 34.96% <64.00%> (+2.78%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@mattrunyon mattrunyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the window in the disconnected state for 2 minutes and when re-enabling network, the "Attempting to reconnect" stays visible. At some point, it attempts to reconnect, but the credentials are invalid. That info should be propagated to the user and prompt them to reload the page to reauthenticate

That error was an uncaught promise though, so might need to be propagated through the JS API in a cleaner way.

Uncaught (in promise) Error: Authentication details invalid
    onEnd http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-internal.js:1
    unary http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-internal.js:1
    rawOnEnd http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-internal.js:1
    rawOnEnd http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-internal.js:1
    onTransportEnd http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-internal.js:1
    $onMessage http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-core.js:19095
    handleEvent_2 http://8f2c-50-24-89-157.ngrok.io/jsapi/dh-core.js:19237

addEventListener: jest.fn(),
subscribeToFieldUpdates: jest.fn(() => () => null),
removeEventListener: jest.fn(),
getTable: jest.fn(),
getObject: jest.fn(),
runCode: jest.fn(),
};
} as unknown) as IdeSession;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to just mock all of IdeSession if it's not a pain. Shouldn't really affect the tests, but if IdeSession changes shape we don't know about it in the tests unless they fail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a pain in the ass. class Table doesn't match the types, missing many methods, and doesn't see the static events (since our typings expect them to be properties instead of static). Cleaning up mock should happen after we start using the actual types published by JS API.
I did a bit of cleanup, but was going down a bit of a yak shaving exercise.

- Mock IdeSession a bit more, add some more mock methods for Table
  - Will finish cleanup after proper types are published
- Listen to RECONNECT_AUTH_FAILED event
@mofojed mofojed requested a review from mattrunyon March 28, 2023 18:01
- TableCsvExporter was depending on Table not having a `freeze` method
- Informs the user an error has occurred and they can press Refresh to try again
@mofojed mofojed requested review from mattrunyon and dsmmcken March 29, 2023 17:33
Copy link
Contributor

@dsmmcken dsmmcken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on the screenshots you sent.

@mofojed mofojed merged commit 15551df into deephaven:main Mar 29, 2023
@mofojed mofojed deleted the jsapi-reconnect branch March 29, 2023 18:50
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support reconnecting to the server
3 participants