cloudfoundry-attic / consul-release

This is a BOSH release for consul.
Apache License 2.0
10 stars 30 forks source link

Handle empty DNS condition in pre-start powershell for windows #87

Closed mwright-pivotal closed 6 years ago

mwright-pivotal commented 6 years ago

At line 53 of consul-release/jobs/consul_agent_windows/templates/pre-start.ps1.erb, need to first check length of array before checking value. In some cases when DNS hadn't been set properly on the VM, the array may be empty causing the script to fail with NullArray error.

Example: PS C:\var\vcap\sys\log\consul_agent_windows> type pre-start.stderr.log
Cannot index into a null array.
At C:\var\vcap\jobs\consul_agent_windows\bin\pre-start.ps1:53 char:4

cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this. Unfortunately, the Pivotal Tracker project is private so you may be unable to view the contents of the story.

The labels on this github issue will be updated when the story is started.

natalieparellano commented 6 years ago

We (garden-windows) are also seeing this in one of our AWS deployments.

We think the issue is with these lines: https://github.com/cloudfoundry-incubator/consul-release/blob/5e78ece3b0eb2fc915cb3de121dbc91c90608d93/jobs/consul_agent_windows/templates/pre-start.ps1.erb#L45-L46

In our deployment that is failing, the first interface happens to be a Hyper-V virtual interface, which does not have any DNS servers associated with it, resulting in a null array.

Instead of grabbing the first interface, we should grab the interface that corresponds with the cell's IP.

For example, the following Powershell will return the DNS servers that we care about:

$ifindex = (Get-NetIPAddress | where {$_.IPAddress -eq  <cell ip>}).InterfaceIndex
Get-DnsClientServerAddress -InterfaceIndex $ifindex -AddressFamily ipv4

cc @sesmith177

evanfarrar commented 6 years ago

This is fixed in #89 and released in v195.