fatedier/frp · warning
local_port new key in section error: %v
Error message
local_port new key in section error: %v
What it means
While expanding a range section, frp creates a derived ini section per port (named prefix_0, prefix_1, ...) via copySection and then calls tmpsection.NewKey('local_port', ...). This error wraps a failure of that NewKey call on the local_port key. go-ini's NewKey fails mainly when the section is frozen or the key/value contains invalid characters (e.g. control bytes or NUL) — with normal configs it essentially never fails.
Source
Thrown at pkg/config/legacy/client.go:328
if len(localPorts) == 0 {
return fmt.Errorf("local_port and remote_port is necessary")
}
// Templates
prefix := strings.TrimSpace(strings.TrimPrefix(section.Name(), "range:"))
for i := range localPorts {
tmpname := fmt.Sprintf("%s_%d", prefix, i)
tmpsection, err := f.NewSection(tmpname)
if err != nil {
return err
}
copySection(section, tmpsection)
if _, err := tmpsection.NewKey("local_port", fmt.Sprintf("%d", localPorts[i])); err != nil {
return fmt.Errorf("local_port new key in section error: %v", err)
}
if _, err := tmpsection.NewKey("remote_port", fmt.Sprintf("%d", remotePorts[i])); err != nil {
return fmt.Errorf("remote_port new key in section error: %v", err)
}
}
return nil
}
func copySection(source, target *ini.Section) {
for key, value := range source.KeysHash() {
_, _ = target.NewKey(key, value)
}
}
// GetDefaultClientConf returns a client configuration with default values.
// Note: Some default values here will be set to empty and will be converted to them
// new configuration through the 'Complete' function to set them as the defaultView on GitHub (pinned to 6c8a8d0a97)
Solutions
- Sanitize the range section's values — plain digits, commas, and dashes only
- If manipulating configs programmatically, do not freeze sections before calling the loader
- Recreate the [range:...] section from scratch rather than patching a corrupted file
Defensive patterns
Strategy: validation
Validate before calling
if !regexp.MustCompile(`^[0-9,\- ]+$`).MatchString(localPortStr) {
return fmt.Errorf("local_port contains invalid characters: %q", localPortStr)
} Prevention
- Restrict range values to digits, commas, and dashes
- Do not feed frozen ini.File objects into the legacy loader
- Recreate corrupted range sections instead of hand-patching
When it happens
Trigger: A range section whose port values, after formatting, contain characters go-ini rejects in a key value, or an ini.File constructed in a frozen/immutable mode; a generated prefix_i section name that collides with an existing frozen section. All are edge cases outside normal file-driven usage.
Common situations: Programmatically building the ini.File with go-ini options that freeze sections; extremely unusual config content copied from binary output introducing control characters.
Related errors
- remote_port new key in section error: %v
- failed to render template for proxy %s: %v
- local_port or remote_port is empty
- local ports number should be same with remote ports number
- local_port and remote_port is necessary
AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15).
Data as JSON: /api/errors/1560ccbd39aa1aed.
Report an issue: GitHub.