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 default

View on GitHub (pinned to 6c8a8d0a97)

Solutions

  1. Sanitize the range section's values — plain digits, commas, and dashes only
  2. If manipulating configs programmatically, do not freeze sections before calling the loader
  3. 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

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


AI-assisted analysis of fatedier/frp@6c8a8d0a97 (2026-08-15). Data as JSON: /api/errors/1560ccbd39aa1aed. Report an issue: GitHub.