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

Backport of agent: prevent empty server_metadata.json into release/1.17.x #19997

Conversation

hc-github-team-consul-core
Copy link
Collaborator

Backport

This PR is auto-generated from #19935 to be assessed for backporting due to the inclusion of the label backport/1.17.

The below text is copied from the body of the original PR.


Description

Remove os.O_TRUNC when agent opens server_metadata.json. This flag seems redundant since we will write the new timestamp to the file immediately. In case the agent crashes in-between OpenServerMetadata and WriteServerMetadata, the server_metadata.json becomes empty, leading to erroneous state where agent can't be started

An alternative way is to continue the agent if server_metadata.json is empty, but this may cause a situation where a very old agent joins a cluster.

Fix: #19720

Testing & Reproduction steps

  1. Start an agent
  2. Stop agent
  3. Remove the content in server_metadata.json
  4. Agent can't be started again
==> Log data will now stream in as it occurs:

2023-12-13T16:11:42.763-0500 [WARN]  agent: BootstrapExpect is set to 1; this is the same as Bootstrap mode.
2023-12-13T16:11:42.763-0500 [WARN]  agent: bootstrap = true: do not enable unless necessary
2023-12-13T16:11:42.765-0500 [DEBUG] agent.grpc.balancer: switching server: target=consul://dc2.5ec3af79-1b29-83eb-c131-a06ecd42120d/server.dc2 from=<none> to=<none>
2023-12-13T16:11:42.768-0500 [WARN]  agent.auto_config: BootstrapExpect is set to 1; this is the same as Bootstrap mode.
2023-12-13T16:11:42.768-0500 [WARN]  agent.auto_config: bootstrap = true: do not enable unless necessary
2023-12-13T16:11:42.769-0500 [INFO]  agent: initialized license: id=7e3af7da-61e8-fc40-8ba9-6e14a4e30b18 expiration="2024-08-21 23:59:59.999 +0000 UTC" features="Automated Backups, Automated Upgrades, Enhanced Read Scalability, Network Segments, Redundancy Zone, Advanced Network Federation, Namespaces, SSO, Audit Logging, Admin Partitions"
2023-12-13T16:11:42.769-0500 [INFO]  agent: started routine: routine=license-manager
2023-12-13T16:11:42.769-0500 [INFO]  agent: started routine: routine=license-monitor
2023-12-13T16:11:42.769-0500 [ERROR] agent: startup error: error="error reading server metadata: unexpected end of JSON input"
^C2023-12-13T16:11:46.757-0500 [INFO]  agent: Caught: signal=interrupt
^C^C2023-12-13T16:11:52.770-0500 [ERROR] agent: startup error: error="error reading server metadata: unexpected end of JSON input"
2023-12-13T16:12:02.772-0500 [ERROR] agent: startup error: error="error reading server metadata: unexpected end of JSON input"

Links

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

Overview of commits

@hc-github-team-consul-core hc-github-team-consul-core requested a review from a team as a code owner December 19, 2023 15:02
@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/gh-19720-empty-server-metadata/officially-game-platypus branch from f68a412 to a7691f0 Compare December 19, 2023 15:02
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved Consul Bot automated PR

@vercel vercel bot temporarily deployed to Preview – consul December 19, 2023 15:08 Inactive
@huikang huikang merged commit 03c94a7 into release/1.17.x Dec 21, 2023
85 checks passed
@huikang huikang deleted the backport/gh-19720-empty-server-metadata/officially-game-platypus branch December 21, 2023 15:05
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

Successfully merging this pull request may close these issues.

3 participants