Skip to content

Commit

Permalink
consoles: Fix constant VNC reconnections when there is a password
Browse files Browse the repository at this point in the history
We would pass a new object to VncConsole.credentials on every render,
which would trigger it to re-connect to the VNC server every time.
This shows up as flicker in the UI, and will also eventually break the
connection entirely, somehow.
  • Loading branch information
mvollmer committed Feb 5, 2025
1 parent 2ee6df4 commit 170341a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/vm/consoles/vnc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Vnc extends React.Component {
isActionOpen: false,
};

this.credentials = null;

this.connect = this.connect.bind(this);
this.onDisconnected = this.onDisconnected.bind(this);
this.onInitFailed = this.onInitFailed.bind(this);
Expand Down Expand Up @@ -121,7 +123,13 @@ class Vnc extends React.Component {
// postpone rendering until consoleDetail is known and channel ready
return null;
}
const credentials = consoleDetail.password ? { password: consoleDetail.password } : undefined;

// We must pass the very same object to VncConsole.credentials
// on every render. Otherwise VncConsole thinks credentials
// have changed and will reconnect.
if (!this.credentials || this.credentials.password != consoleDetail.password)
this.credentials = { password: consoleDetail.password };

const encrypt = this.getEncrypt();
const renderDropdownItem = keyName => {
return (
Expand Down Expand Up @@ -170,7 +178,7 @@ class Vnc extends React.Component {
path={path}
encrypt={encrypt}
shared
credentials={credentials}
credentials={this.credentials}
vncLogging={ window.debugging?.includes("vnc") ? 'debug' : 'warn' }
onDisconnected={this.onDisconnected}
onInitFailed={this.onInitFailed}
Expand Down

0 comments on commit 170341a

Please sign in to comment.