fix: rebuild stream router when services change#13318
Open
shreemaan-abhishek wants to merge 3 commits intoapache:masterfrom
Open
fix: rebuild stream router when services change#13318shreemaan-abhishek wants to merge 3 commits intoapache:masterfrom
shreemaan-abhishek wants to merge 3 commits intoapache:masterfrom
Conversation
Cover the four scenarios the fix addresses end-to-end via stream sockets: service status disable, re-enable, deletion, and recreation. Each asserts that route matching reflects the new service state once the rebuild path runs. Ports the test file from api7-ee apache#1417 (the source PR for this backport) which was omitted from the initial port.
nic-6443
previously approved these changes
Apr 30, 2026
membphis
previously approved these changes
Apr 30, 2026
AlinsRan
previously approved these changes
Apr 30, 2026
The previous commit started rebuilding the stream router whenever
services.conf_version changes, but the rebuild produced the same
routing decisions because create_router() didn't actually consult
service status — service_fetch wasn't even imported in this file.
Add the missing service_id enforcement at the top of the iteration
loop:
- If a stream_route references a service_id whose service can't be
fetched (deleted, or not yet synced from etcd), log
'failed to fetch service configuration by id: <id>' and skip
the route.
- If the service status is 0 (explicitly disabled), skip the route.
Combined with the conf_version trigger from the previous commit, a
service status flip / delete / late-sync now propagates into routing
decisions on the next match() call.
This is what the integration tests added in
t/stream-node/service-change-rebuild-router.t exercise; without this
patch, TESTs 2-4 fail because the disabled / deleted service is
ignored at routing time.
Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
504bc1b
AlinsRan
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The stream router in
apisix/stream/router/ip_port.luaonly trackedstream_routes.conf_versionto decide when to rebuild the internal router. As a result, updates to a service referenced by a stream route did not trigger a rebuild, so changes such as a service arriving after the route, status updates, or deletion were not consistently reflected. Additionally, when a rebuild produced zero TLS routes, the previously builttls_routerwas left in place and could keep dispatching against stale routes. This change tracks the servicesconf_versionalongside the stream routes version and rebuilds the router when either changes, and resetstls_routerto nil when the rebuild yields no TLS routes.Which issue(s) this PR fixes:
Fixes #
Checklist