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

panic parsing JSON config file #1290

Closed
The-Loeki opened this issue Jun 15, 2016 · 3 comments
Closed

panic parsing JSON config file #1290

The-Loeki opened this issue Jun 15, 2016 · 3 comments

Comments

@The-Loeki
Copy link

The-Loeki commented Jun 15, 2016

Nomad version

0.3.2
0.4.0-rc1

Operating system and Environment details

CentOS 7 64-bit
Ubuntu 16.04 64-bit

Issue

When a config file:

  • is a JSON file
  • has any section in it
    • with only one key
    • which is a dict

Nomad agent panics with an index-out-of-range.

Reproduction steps

root@n01:~# cat /etc/nomad/doeswork.hcl
client {
    options {
        driver.whitelist = "docker"
    }
}
root@n01:~# cat /etc/nomad/borking-config.json
{
  "client": {
    "options": {
      "driver.whitelist": "docker"
    }
  }
}
root@n01:~# /usr/local/bin/nomad agent -log-level=DEBUG -config /etc/nomad/doeswork.hcl 
root@n01:~# /usr/local/bin/nomad agent -log-level=DEBUG -config /etc/nomad/borking-config.json 

Nomad Client logs

root@n01:~# /usr/local/bin/nomad agent -version
Nomad v0.4.0-dev ('bc09a0444722617a3a0ee0daa28d24b93d9d3e5b+CHANGES'
root@n01:~# /usr/local/bin/nomad agent -log-level=DEBUG -config /etc/nomad/doeswork.hcl 
==> Must specify either server, client or dev mode for the agent.
root@n01:~# /usr/local/bin/nomad agent -log-level=DEBUG -config /etc/nomad/borking-config.json 
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x11b6100, 0xc820010070)
    /opt/go/src/runtime/panic.go:481 +0x3e6
github.com/hashicorp/nomad/command/agent.parseClient(0xc82000de80, 0xc8201e20c0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/config_parse.go:298 +0xbc7
github.com/hashicorp/nomad/command/agent.parseConfig(0xc82000de00, 0xc820149a40, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/config_parse.go:145 +0x8e7
github.com/hashicorp/nomad/command/agent.ParseConfig(0x7f66f0d97258, 0xc820026150, 0xc820026150, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/config_parse.go:63 +0x33d
github.com/hashicorp/nomad/command/agent.ParseConfigFile(0x7fff4d5fe859, 0x1e, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/config_parse.go:30 +0x151
github.com/hashicorp/nomad/command/agent.LoadConfig(0x7fff4d5fe859, 0x1e, 0x3, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/config.go:813 +0x135
github.com/hashicorp/nomad/command/agent.(*Command).readConfig(0xc82014c640, 0x1231520)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/command.go:141 +0x119f
github.com/hashicorp/nomad/command/agent.(*Command).Run(0xc82014c640, 0xc82000a070, 0x3, 0x3, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/command/agent/command.go:380 +0x1a3
github.com/hashicorp/nomad/vendor/github.com/mitchellh/cli.(*CLI).Run(0xc8200c2480, 0xc8200c2480, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/nomad/vendor/github.com/mitchellh/cli/cli.go:153 +0x5ee
main.RunCustom(0xc82000a060, 0x4, 0x4, 0xc82010f050, 0xc8200160b8)
    /opt/gopath/src/github.com/hashicorp/nomad/main.go:55 +0x4d5
main.Run(0xc82000a060, 0x4, 0x4, 0x1cf4350)
    /opt/gopath/src/github.com/hashicorp/nomad/main.go:20 +0x4c
main.main()
    /opt/gopath/src/github.com/hashicorp/nomad/main.go:16 +0x60

RCA

I'm no go expert, but looking at
https://github.com/hashicorp/nomad/blob/v0.4.0-rc1/command/agent/config_parse.go#L144
I'd say the client section gets detected & passed on to https://github.com/hashicorp/nomad/blob/v0.4.0-rc1/command/agent/config_parse.go#L298 which is the source of the panic.

So, considering o := list.Filter("any-section"); len(o.Items) > 0 and o.Elem().Items[0] eventually does not exist, but only for JSON, I'm pretty stumped.

The weird thing is, analysing further it only happens if there's a single dict in the section, this will bork:

{
"server": {
  "not-even-valid": {}
}
}

and this will work (as in config error of course):

{
"server": {
  "not-even-valid": true
}
}
@bsphere
Copy link

bsphere commented Aug 4, 2016

the exact thing happens with the following json after adding the client key -
{"bind_addr": "0.0.0.0", "advertise": {"http": "127.0.0.1:4646", "rpc": "172.31.51.51:4647", "serf": "172.31.51.51:4648"}, "client": {"options": {"docker.privileged.enabled": "true"}}}

@amfern
Copy link

amfern commented Nov 29, 2018

same happens for me {"client": {"options": {}}}

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants