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

Dependency cycle when postgresql::globals::encoding is set #1631

Open
crazymind1337 opened this issue Feb 10, 2025 · 10 comments
Open

Dependency cycle when postgresql::globals::encoding is set #1631

crazymind1337 opened this issue Feb 10, 2025 · 10 comments

Comments

@crazymind1337
Copy link

crazymind1337 commented Feb 10, 2025

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.

@kenyon
Copy link
Contributor

kenyon commented Feb 11, 2025

Same as #1543?

@crazymind1337
Copy link
Author

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
Copy link
Author

crazymind1337 commented Feb 11, 2025

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
Copy link
Author

crazymind1337 commented Feb 11, 2025

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

@crazymind1337
Copy link
Author

crazymind1337 commented Feb 11, 2025

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@ShadNex
Copy link

ShadNex commented Feb 19, 2025

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

@crazymind1337
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants