Skip to content

Commit

Permalink
use roomid to verify reset
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Jan 22, 2024
1 parent f48ddd7 commit 111ca1a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class Room {
isLarge,
region,
id,
uid,
roomId: this.roomId,
}
);
}
Expand Down
16 changes: 8 additions & 8 deletions server/vm/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ export abstract class VMManager {
return { ...selected, assignTime: Number(new Date()) };
};

public resetVM = async (vmid: string, uid?: string): Promise<void> => {
if (uid !== undefined) {
// verify the uid matches if user initiated
public resetVM = async (vmid: string, roomId?: string): Promise<void> => {
if (roomId !== undefined) {
// verify the roomId matches if user initiated
const { rows } = await postgres.query(
`SELECT uid FROM vbrowser WHERE pool = $1 AND vmid = $2`,
`SELECT "roomId" FROM vbrowser WHERE pool = $1 AND vmid = $2`,
[this.getPoolName(), vmid]
);
if (rows[0]?.uid && rows[0]?.uid !== uid) {
if (rows[0]?.roomId && rows[0]?.roomId !== roomId) {
console.log(
'[RESET] uid mismatch on %s, expected %s, got %s',
'[RESET] roomId mismatch on %s, expected %s, got %s',
vmid,
rows[0]?.uid,
uid
rows[0]?.roomId,
roomId
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion server/vmWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ app.post('/releaseVM', async (req, res) => {
req.body.provider + (req.body.isLarge ? 'Large' : '') + req.body.region
];
if (req.body.id) {
await pool?.resetVM(req.body.id, req.body.uid);
await pool?.resetVM(req.body.id, req.body.roomId);
}
return res.end();
} catch (e) {
Expand Down

0 comments on commit 111ca1a

Please sign in to comment.