puppetlabs-postgresql icon indicating copy to clipboard operation
puppetlabs-postgresql copied to clipboard

Dependency cycle when `postgresql::globals::encoding` is set

Open crazymind1337 opened this issue 9 months ago • 10 comments

Describe the Bug

While upgrading the module from 9.1.0 to 10.5.0 we ran into the issue of a dependency cycle, when setting a value for postgresql::globals::encoding.

Info: Applying configuration version '*****.puppetserver01-atm_10130-1e601b89123d47539e44cf03bd0dce23a8d9a166'
Error: Found 1 dependency cycle:
(Anchor[postgresql::server::service::begin::main] => Postgresql_psql[Set template1 encoding to UTF-8] => Postgresql::Server::Instance::Late_initdb[main] => Postgresql::Server::Instance::Initdb[main] => Postgresql_conf[port_for_instance_main] => Postgresql::Server::Instance::Service[main] => Anchor[postgresql::server::service::begin::main])

Expected Behavior

No dependency cycle.

Steps to Reproduce (hiera)

---
classes:
  - postgresql::server

postgresql::globals::encoding: 'UTF-8'

Steps to Reproduce (docker)

docker run -it --rm ubuntu:22.04 bash

apt-get update
apt-get install -y wget

wget https://apt.puppetlabs.com/puppet-release-jammy.deb
dpkg -i puppet-release-jammy.deb
apt-get update
apt-get install -y puppet-agent

/opt/puppetlabs/bin/puppet module install puppetlabs-postgresql

/opt/puppetlabs/bin/puppet apply -e "
  class { 'postgresql::globals': encoding => 'UTF-8', }
  class { 'postgresql::server': }
"

Environment

  • Module version 10.5.0
  • Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04

Additional Context

Removing the value will compile and apply successful.

crazymind1337 avatar Feb 10 '25 09:02 crazymind1337

Same as #1543?

kenyon avatar Feb 11 '25 00:02 kenyon

Seems to be the same with the little difference they are setting encoding via Class postgresql::server. I am setting it via postgresql::server::globals.

crazymind1337 avatar Feb 11 '25 07:02 crazymind1337

Using the parameter postgresql::server::encoding works on our nodes, but it does not work with the same classes in our rspec tests, which is extremly strange.

Anyways - it has to work also with postgresql::globals::encoding on nodes and rspec. I tried to check which dependency could cause the problem. But I find it very hard since there are so many difference dependencies set in different files.

crazymind1337 avatar Feb 11 '25 07:02 crazymind1337

Added Steps to Reproduce (docker) to the initial post.

crazymind1337 avatar Feb 11 '25 08:02 crazymind1337

And while testing the steps from Steps to Reproduce (docker) with a changed command it still fails with a dependency cycle.

/opt/puppetlabs/bin/puppet apply -e "class { 'postgresql::server': encoding => 'UTF-8', }"
root@4eea8d3588b3:/# /opt/puppetlabs/bin/puppet apply -e "class { 'postgresql::server': encoding => 'UTF-8', }"
Notice: Compiled catalog for 4eea8d3588b3 in environment production in 0.09 seconds
Error: Found 1 dependency cycle:
(Anchor[postgresql::server::service::begin::main] => Postgresql_psql[Set template1 encoding to UTF-8] => Postgresql::Server::Instance::Late_initdb[main] => Postgresql::Server::Instance::Initdb[main] => Postgresql_conf[port_for_instance_main] => Postgresql::Server::Instance::Service[main] => Anchor[postgresql::server::service::begin::main])\nTry the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
Error: Failed to apply catalog: One or more resource dependency cycles detected in graph

Very very odd.

crazymind1337 avatar Feb 11 '25 08:02 crazymind1337

Well I think I found the issue - it is at https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/instance/late_initdb.pp#L46 and https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/lib/puppet/type/postgresql_psql.rb#L137

postgresql_psql { "Set template1 encoding to ${encoding}": is set to but run before Anchor["postgresql::server::service::end::${name}"], but in type there is a autorequire set to the same resource.

Thats the actual dependency cycle. I will test this.

crazymind1337 avatar Feb 11 '25 09:02 crazymind1337

Commenting out https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/instance/late_initdb.pp#L46 does NOT fix the issue.

The depedency cycle still happens for me if using the latest state of main.

crazymind1337 avatar Feb 11 '25 09:02 crazymind1337

As deeper I get into the modules code as more confused I am getting...

crazymind1337 avatar Feb 11 '25 09:02 crazymind1337

Running into the same issue myself in our environment. After removing postgresql::globals::encoding it works. @crazymind1337 were you able to find out more?

ShadNex avatar Feb 19 '25 07:02 ShadNex

Sadly I had no more time to investigate. But I think this module requires some general refactoring including the removal of those anchors. Again sadly I have no time for that.

crazymind1337 avatar Feb 20 '25 16:02 crazymind1337

this seems like its probably related to https://github.com/puppetlabs/puppetlabs-postgresql/pull/1564

b4ldr avatar Jul 11 '25 14:07 b4ldr