Skip to content

fix panic due to empty gw#579

Open
Abirdcfly wants to merge 1 commit intokubeedge:mainfrom
Abirdcfly:fixrange
Open

fix panic due to empty gw#579
Abirdcfly wants to merge 1 commit intokubeedge:mainfrom
Abirdcfly:fixrange

Conversation

@Abirdcfly
Copy link
Member

What type of PR is this?
/kind bug

What this PR does / why we need it:

I1010 16:32:46.078267       1 tunnel.go:131] [MDNS] Discovery found peer: {12D3KooWFzqKr5PhTuKCsry9Cyo3DtvMDrK5HenyTfRMzDgyCraL: [/ip4/172.31.10.125/tcp/20006 /ip4/169.254.25.10/tcp/20006 /ip4/127.0.0.1/tcp/20006 /ip4/10.62.48.116/tcp/20006]}
panic: runtime error: index out of range [0] with length 0

goroutine 764 [running]:
github.com/kubeedge/edgemesh/pkg/gateway.(*Server).newProto.func1({0x3b01d68?, 0x1f55d80?}, {0x2153880?, 0xc0008ee880?})
        /code/pkg/gateway/server.go:164 +0x1a7
sync.(*Map).Range(0x3b01d60?, 0xc000717b38)
        /usr/local/go/src/sync/map.go:354 +0x2b8
github.com/kubeedge/edgemesh/pkg/gateway/cache.RangeVirtualServices(...)
        /code/pkg/gateway/cache/cache.go:73
github.com/kubeedge/edgemesh/pkg/gateway.(*Server).newProto(0xc00066d5f0, {0x2737c98?, 0xc00037a078})
        /code/pkg/gateway/server.go:171 +0xa6
github.com/kubeedge/edgemesh/pkg/gateway.(*Server).serve(0xc00066d5f0)
        /code/pkg/gateway/server.go:142 +0x925
created by github.com/kubeedge/edgemesh/pkg/gateway.NewServer
        /code/pkg/gateway/server.go:68 +0x165

when there is a gw that Spec.Gateways is empty, there is a panic, note this gateway may not related with kubeedge, it is may just normal istio gateway

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@kubeedge-bot kubeedge-bot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 10, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @Abirdcfly, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the edgemesh gateway component that caused a runtime panic. The panic was triggered when the system attempted to access the first element of an empty Spec.Gateways slice within a VirtualService object. The fix introduces a defensive check to ensure the slice is not empty before indexing, thereby preventing the "index out of range" error and improving the stability of the gateway's virtual service discovery.

Highlights

  • Panic Fix: Addressed a runtime panic that occurred when processing VirtualService objects with an empty Spec.Gateways field, preventing an "index out of range" error.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign fisherxu after the PR has been reviewed.
You can assign the PR to them by writing /assign @fisherxu in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 10, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a panic caused by accessing an empty Spec.Gateways slice in a virtual service. The fix correctly adds a bounds check before accessing the slice. My review includes a suggestion to further improve the logic by iterating through all gateways in the list, rather than just checking the first one, to ensure correct behavior when a virtual service is associated with multiple gateways.

Comment on lines +164 to 167
if len(vs.Spec.Gateways) > 0 && vs.Spec.Gateways[0] == srv.options.GwName &&
reflect.DeepEqual(vs.Spec.Hosts, srv.options.Hosts) {
vss = append(vss, vs)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While your change correctly prevents the panic, it only considers the first gateway listed in vs.Spec.Gateways. A VirtualService can be bound to multiple gateways, and this implementation will fail to find a match if the intended gateway is not the first in the list.

To make the logic more robust and align with the intended behavior of virtual services, I suggest iterating over the vs.Spec.Gateways slice to check for a match.

for _, gw := range vs.Spec.Gateways {
					if gw == srv.options.GwName && reflect.DeepEqual(vs.Spec.Hosts, srv.options.Hosts) {
						vss = append(vss, vs)
						break
					}
				}

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants