As discussed with @mitchellh and @phinze we don’t need to randomize in
order to get infinite ID’s. When we hit the highest possible number and
add `1` it will just wrap back to `0`, which is just fine with regards
to how Terraform works and uses these ID’s.
Tested this by setting the initial value of `m.nextId` to `4294967293`
where the maximum is `4294967295 `. So with some additional logging it
clearly showed it wrapped and continued without any issues.
Currently Terraform is leaking goroutines and with that memory. I know
strictly speaking this maybe isn’t a real concern for Terraform as it’s
mostly used as a short running command line executable.
But there are a few of us out there that are using Terraform in some
long running processes and then this starts to become a problem.
Next to that it’s of course good programming practise to clean up
resources when they're not needed anymore. So even for the standard
command line use case, this seems an improvement in resource management.
Personally I see no downsides as the primary connection to the plugin
is kept alive (the plugin is not killed) and only unused connections
that will never be used again are closed to free up any related
goroutines and memory.