chika0801 / hysteria-install

Hysteria 2 安装指南
https://github.com/apernet/hysteria
168 stars 218 forks source link

YAML server config gives error, JSON works fine #3

Closed us254 closed 1 year ago

us254 commented 1 year ago

Hello, I’m using hysteria 2, as a server and I encountered a problem with the YAML config format. When I use the YAML config, I get an error message like this:

journalctl -u hysteria
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 systemd[1]: Started hysteria.service.
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: panic: runtime error: index out of range [-1]
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: goroutine 1 [running]:
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/yosuke-furukawa/json5/encoding/json5.stateInStringKey(0xc0000b51>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/yosuke-furukawa/json5@v0.1.1/encoding/json5/scanner.go:4>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/yosuke-furukawa/json5/encoding/json5.checkValid({0xc0001f2400, 0>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/yosuke-furukawa/json5@v0.1.1/encoding/json5/scanner.go:2>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/yosuke-furukawa/json5/encoding/json5.Unmarshal({0xc0001f2400, 0x>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/yosuke-furukawa/json5@v0.1.1/encoding/json5/decode.go:73>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: main.parseServerConfig({0xc0001f2400, 0xcb, 0x200})
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/apernet/hysteria/app/cmd/server.go:302 +0x56
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: main.glob..func5(0x18af020?, {0xffb627?, 0x2?, 0x2?})
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/apernet/hysteria/app/cmd/main.go:134 +0x1ff
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/spf13/cobra.(*Command).execute(0x18af020, {0xc00007f5a0, 0x2, 0x>
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/spf13/cobra@v1.6.1/command.go:920 +0x847
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/spf13/cobra.(*Command).ExecuteC(0x18aea60)
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bd
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: github.com/spf13/cobra.(*Command).Execute(...)
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/spf13/cobra@v1.6.1/command.go:968
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]: main.main()
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 hysteria[5389]:         github.com/apernet/hysteria/app/cmd/main.go:209 +0x25
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 systemd[1]: hysteria.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Jun 24 14:48:33 ubuntu-4gb-fsn1-3 systemd[1]: hysteria.service: Failed with result 'exit-code'.
Jun 24 14:48:43 ubuntu-4gb-fsn1-3 systemd[1]: hysteria.service: Scheduled restart job, restart counter is at 1.
Jun 24 14:48:43 ubuntu-4gb-fsn1-3 systemd[1]: Stopped hysteria.service.
Jun 24 14:48:43 ubuntu-4gb-fsn1-3 systemd[1]: Started hysteria.service.
Jun 24 14:48:43 ubuntu-4gb-fsn1-3 hysteria[5397]: panic: runtime error: index out of range [-1]
Jun 24 14:48:43 ubuntu-4gb-fsn1-3 hysteria[5397]: goroutine 1 [running]:

However, when I convert the YAML config to JSON format, it works fine. Here is the YAML config that I used:

listen: :443

tls:
  cert: /root/fullchain.cer
  key: /root/private.key

auth:
  type: password
  password: chika

masquerade:
  type: proxy
  proxy:
    url: https://www.deepl.com
    rewriteHost: true 

And here is the JSON config that works:

{
  "listen": ":443",
  "tls": {
    "cert": "/root/fullchain.pem",
    "key": "/root/privkey.pem"
  },
  "auth": {
    "type": "password",
    "password": "xxxxxxx"
  },
  "masquerade": {
    "type": "proxy",
    "proxy": {
      "url": "https://www.deepl.com",
      "rewriteHost": true
    }
  }
}

I’m not sure what is causing this issue, but it seems like there is a bug with the YAML parser. Could you please look into this and fix it? Thank you for your great work on hysteria.

chika0801 commented 1 year ago

Sorry, I don't understand the problem either.

I suggest you can go here https://github.com/apernet/hysteria/issues for help.

Or join hysteria's telegram https://t.me/hysteria_github which has a group for hysteria 2 feedback where you can give feedback to the developers.

I'm not in a position to help you with that.