Skip to content

secrets edit should maintain the websocket as long as the editor session is alive #315

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

Closed
CMCDragonkai opened this issue Oct 23, 2024 · 4 comments · Fixed by #320
Closed
Assignees
Labels
development Standard development

Comments

@CMCDragonkai
Copy link
Member

Specification

When using secrets edit, it will timeout if the editor session isn't finished fast enough. I opened up the secrets edit and waited for a while, after trying to save, it failed:

cmcdragonkai ➜ matrix-framework-13-ryzen-7040  ➜ ~/Projects/Polykey-CLI
 $ ./dist/polykey.js secrets ed nix:/nix.conf
ERROR:polykey.PolykeyClient.WebSocketClient:ErrorWebSocketConnectionKeepAliveTimeOut: WebSocket Connection reached keep-alive timeout - 
ERROR:polykey.PolykeyClient.WebSocketClient.WebSocketConnection 0:ErrorWebSocketConnectionKeepAliveTimeOut: WebSocket Connection reached keep-alive timeout - 
ErrorWebSocketConnectionNotRunning

We need to make the websocket connection alive for as long as the editor session is alive, it shouldn't fail.

That being said it's also important not to start a vault commit transaction until the editor has in fact finished writing. We don't want this to block other secret operations. Concurrent testing needs to be checked too.

Tasks

  1. Use a stream life cycle to be maintained while the editor is there, it shouldn't expire on the keep alive timeout.
  2. Test that secrets edit can work for a long running edit.
  3. Test that while the editor is open it doesn't cause blocked concurrent secrets operations.

@tegefaulkes @aryanjassal

@CMCDragonkai CMCDragonkai added the development Standard development label Oct 23, 2024
@CMCDragonkai
Copy link
Member Author

I want to point out that this message looks weird too:

INFO:polykey.PolykeyAgent.ClientService.WebSocketServer.WebSocketConnection 0:ErrorWebSocketConnectionPeer: WebSocket Connection peer error - Peer closed with code 1000

This looks like a error. But it's actually a successful close. It's considered normal closure.

@aryanjassal
Copy link
Member

I also encountered this issue. After a short discussion with Brian, our conclusion was that this is being caused due to the execSync block launching the editor. The execSync might be blocking everything else from running, which might include the websocket pings, and that might be causing this issue.

After Polykey-CLI#305 is completed, I can start work on this issue.

@aryanjassal aryanjassal self-assigned this Oct 25, 2024
@aryanjassal aryanjassal changed the title Secrets Edit Command needs to Maintain Websocket Keepalive Timeout as long as the Editor Session is Alive secrets edit should maintain the websocket as long as the editor session is alive Oct 28, 2024
Copy link
Member

aryanjassal commented Oct 28, 2024

After some quick investigation, I have realised that execSync does, in fact, block everything until the command is finished. To resolve this, an async exec is needed.

try {
  const stdout = await new Promise((resolve, reject) => {
    exec(command, (error, stdout, stderr) => {
      if (error) {
        reject(error);
      } else if (stderr) {
        reject(new Error(stderr));
      } else {
        resolve(stdout);
      }
    });
  });
} catch (e) {
  // Promise rejected. There was an error.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development
Development

Successfully merging a pull request may close this issue.

2 participants