Hi everyone!
I have a quite a pickle in my game server routing handling. I’m creating fly machines on demand using the machines api. They are created fine, and everything works really well… If I have only one machine running. I’m using fly-replay
and fly-force-instance-id
to route my requests to the correct game server instance. There are basically two requests that happen:
- A regular http get request that gets the game map for the user. This is routed to random game server as well.
- A ws upgrade request. This is routed to random game server.
This is my gateway application, it is really simple and as I said, it works, but the problem is only that the replay goes to wrong machine Any ideas what the problem could be?
import { Hono } from 'hono'
import { cors } from 'hono/cors'
import { csrf } from 'hono/csrf'
const app = new Hono()
app.use(
'*',
cors({
origin: [
// Origins
],
})
)
app.use(
'*',
csrf({
origin: [
// Origins
],
})
)
app.onError((error, c) => {
console.error(`${error}`)
return c.json({ error, message: error.message || 'Custom Error Message' }, 500)
})
app.get('*', (c) => {
const region = c.req.header('region') ?? c.req.query('region')
const instance = c.req.header('instance') ?? c.req.query('instance')
if (!region || !instance) {
throw new Error('Machine not found')
}
console.log(
'replaying',
`region=${region};app=floating-islands-game-server;fly-force-instance-id=${instance}`
)
c.header(
'fly-replay',
`region=${region};app=floating-islands-game-server;fly-force-instance-id=${instance}`
)
return c.body('OK')
})
export default {
fetch: app.fetch,
port: 8080,
hostname: '0.0.0.0',
}
I’m getting seemingly ok logs, but they seem to not go to the right machine:
2024-12-06T12:26:31.547 app[48e5376b3d9128] ams [info] replaying region=ams;app=floating-islands-game-server;fly-force-instance-id=9185954bd43518
2024-12-06T12:26:32.899 app[48e5376b3d9128] ams [info] replaying region=ams;app=floating-islands-game-server;fly-force-instance-id=9185954bd43518