fix: clean up in-memory connector after delete.#4529
fix: clean up in-memory connector after delete.#4529loafoe wants to merge 1 commit intodexidp:masterfrom
Conversation
d53abf3 to
f1fe617
Compare
f1fe617 to
7b3402c
Compare
7b3402c to
da2cb7e
Compare
da2cb7e to
2ea7667
Compare
17ea62a to
ddbfe80
Compare
|
@nabokihms added a test that demonstrates the issue. The test proves that without the CloseConnector calls in CreateConnector and DeleteConnector, the server would reuse a stale in-memory instance of the connector if the ResourceVersion happened to match. Also rebased to latest |
|
@loafoe I tested the test
We need to close on creating only if someone deletes the connector from the database manually (not through the API), e.g., by deleting a row from Postgres or a resource from Kubernetes. This is ok, we can leave closing on creating, but I just want a proper comment in the code for this specific case. |
Ensures the cache is invalidated whenever a connector is created or removed, forcing the server to re-initialize it with the latest configuration on its next use. Signed-off-by: Andy Lo-A-Foe <andy.loafoe@gmail.com>
ddbfe80 to
959e1b6
Compare
thanks @nabokihms for going through the test code. I've removed the close on delete and left it in the create path with a comment. All tests still pass. |
Overview
Fixes stale references to Connector when re-adding under same id
What this PR does / why we need it
I've investigated and fixed the issue where connectors provisioned via the gRPC API would retain old configurations after being deleted and recreated.
The root cause was that Dex's Server maintains an in-memory cache of opened connectors. When a connector is retrieved, Dex compares its ResourceVersion in storage with the one in the cache. Since the gRPC CreateConnector call hardcodes the ResourceVersion to "1", deleting and recreating a connector with the same ID resulted in matching versions, causing the server to continue using the stale, cached connector object.
I implemented the following changes to resolve this:
CloseConnector(id string)toServer: This new method safely removes a connector from the server's in-memory cache.All existing server tests passed.
Special notes for your reviewer
Fixes #4528