[Bug]: A gateway shows as inactive while another platform-api replica still holds its session

Open
#4,321 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, go, postgresql

Research direction

Start with platform-api/internal/handler/websocket.go around line 170 and trace how session closure updates the gateway's active state. Check how gateway sessions are represented across replicas and whether the shared Postgres-backed state can determine if any session remains. Done means isActive stays true when another replica still has a live session; add or update coverage for the two-replica case.

Written by the indexing model from the issue text.

Description

Area/Platform-API Aspect/API Severity/Major Type/Bug
Please select the area the issue is related to

Platform API

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

With more than one platform-api replica, a gateway is reported as inactive ("isActive": false) while it still has a live session on another replica.

When a gateway's WebSocket session closes, the replica that held it marks the whole gateway inactive if that replica has no other session for it (platform-api/internal/handler/websocket.go:170, len(h.manager.GetConnections(gateway.ID)) == 0). GetConnections only knows this replica's in-memory sessions, so a session the gateway holds on another replica is not counted.

A gateway can have two active tokens, and so two controllers connected at once, each possibly on a different replica. In that case, when one session ends, the gateway shows inactive while the other is still connected and serving. The console shows such a gateway as "Not Active" and greys out its Deploy button (seen on the Deploy page for an inactive gateway).

Since #4315 (revoking a token closes the sessions opened with it), revoking one of the two tokens also triggers this.

Expected: isActive stays true while any replica holds a session for the gateway.
Actual: it becomes false as soon as one replica loses its last session for that gateway.

Related: #1185 (reconnect not updating the state, single replica; closed).

Steps to Reproduce
  1. Run two platform-api replicas, P1 and P2, on one shared Postgres database, each on its own ports.
  2. Register a gateway (POST /api/v0.9/gateways) and mint two tokens for it (POST /api/v0.9/gateways/<id>/tokens twice).
  3. Start one gateway controller with token 1, connected to P1, and a second controller for the same gateway with token 2, connected to P2.
  4. GET /api/v0.9/gateways/<id> returns "isActive": true; P1 and P2 each hold one session for the gateway.
  5. Stop the first controller (docker stop <controller-1>). P1 logs WebSocket connection closed for its session.
  6. GET /api/v0.9/gateways/<id> returns "isActive": false at 2, 8 and 30 seconds after the stop. The second controller is still running and connected to P2, which still holds its session.
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)
  • Source: main at a9992d2fe.
  • Two platform-api replicas built from source, sharing a postgres:17-alpine database (schema from schema.postgres.sql).
  • Gateway controllers and runtimes built from that commit (version 2026.09.24).
  • macOS with Rancher Desktop.
Dominant language
Go
Stars
85
Forks
137
Avg merge
1d 12h
Merged PRs (30d)
247

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.