Skip to content

Commit

Permalink
fix(server): terminate ws connection if server not ready
Browse files Browse the repository at this point in the history
Previously we were exiting early from the websocket connection handler
if the server wasn't ready but not terminating the actual connection.

This meant that a client could be connected but websocket
messages were otherwise not handled.

Now we simply terminate the connection so that clients can retry.
  • Loading branch information
eysi09 committed Oct 5, 2022
1 parent 88daa4c commit 6dc50d2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ export class GardenServer {
const wsRouter = new Router()

wsRouter.get("/ws", async (ctx) => {
// The typing for koa-websocket isn't working currently
const websocket: Koa.Context["ws"] = ctx["websocket"]

if (!this.garden) {
return this.notReady(ctx)
this.log.debug("Server not ready.")
websocket.terminate()
return
}

const connId = uuidv4()

// The typing for koa-websocket isn't working currently
const websocket: Koa.Context["ws"] = ctx["websocket"]

// Helper to make JSON messages, make them type-safe, and to log errors.
const send = <T extends ServerWebsocketMessageType>(type: T, payload: ServerWebsocketMessages[T]) => {
const event = { type, ...(<object>payload) }
Expand Down

0 comments on commit 6dc50d2

Please sign in to comment.