Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gate (v0.31.2) breaks cachePingTTL parsing for Lite Mode #223

Closed
ddx0 opened this issue Jul 22, 2023 · 1 comment
Closed

gate (v0.31.2) breaks cachePingTTL parsing for Lite Mode #223

ddx0 opened this issue Jul 22, 2023 · 1 comment

Comments

@ddx0
Copy link

ddx0 commented Jul 22, 2023

Arch: x86_64
Go version: go1.20.6 linux/amd64

Tested on:

  • OS: Debian GNU/Linux 12 (bookworm) / Kernel: 6.1.0-10-amd64
  • OS: Fedora Linux 38 (Workstation Edition) / Kernel: 6.3.12-200.fc38.x86_64

I've been doing some testing of the latest Gate proxy versions lately, and a couple of days ago I had mentioned how v0.31.1 was unable to parse -1 or "-1" properly, referenced here: #221

A simple workaround was to simply pass "-1s", which seemed to do the trick.

The latest commit (59afe39), which attempts to solve the parsing issue however, seems to unfortunately break cachePingTTL parsing altogether:

Error logs

error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `-1s` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `-1` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `0s` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `0` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `1s` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `1` into configutil.Duration
error reading config file "/home/server/minecraft/proxy/testing/config.yml": error unmarshaling config file "/home/server/minecraft/proxy/testing/config.yml" to *config.Config: yaml: unmarshal errors:
  line 10: cannot unmarshal !!str `60s` into configutil.Duration

The configuration used was:

config.yml

config:
  bind: 0.0.0.0:25565
  proxyProtocol: false
  lite:
    enabled: true
    routes:
      - host: ["*"]
        backend: 127.0.0.1:25565
        proxyProtocol: false
        cachePingTTL: "60s"

I'm not experienced with Go but I did attempt to debug as best I could.

At line 625 in yaml/decode.go (https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/decode.go#L625), an attempt to resolve the type in a switch statement results in something like:

interface {}(string) "-1s"

which will switch on case string @ line 647 (https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/decode.go#L647), but will fail to equate to a durationType (https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/decode.go#L332), thereby skipping the time.ParseDuration statement on the next line.

Interestingly, I don't think the wrapper functions introduced in (https://github.com/minekube/gate/blob/master/pkg/util/configutil/duration.go) are ever called. No breakpoints seemed to hit them. I wonder if this has to do with it being recognized as a string and not of it's respective type, possibly previously mentioned here #218 and here spf13/viper#338 (comment)

How to reproduce:

  1. Manually download the binary at https://github.com/minekube/gate/releases/tag/v0.31.2.
  2. Have a config.yml file using Lite-Mode, with the cachePingTTL value set to a numerical value with or without the "s" appended.
  3. Attempt to run proxy.

Caveats:

  • Only tested using native Go binaries, and did not test with Docker or Kubernetes
  • Only tested cachePingTTL for Lite-Mode
@robinbraemer
Copy link
Member

Thanks, I’ll look into it asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants