Skip to content

fix: add a retry for unsetting environment variable in content_restart()#499

Merged
karawoo merged 4 commits intomainfrom
kara-restart-env-vars
Feb 13, 2026
Merged

fix: add a retry for unsetting environment variable in content_restart()#499
karawoo merged 4 commits intomainfrom
kara-restart-env-vars

Conversation

@karawoo
Copy link
Collaborator

@karawoo karawoo commented Feb 13, 2026

Intent

content_restart() sets and immediately unsets an environment variable to restart content on Connect. However sometimes the unsetting is not working, leading to a proliferation of env vars. I believe that in these cases the error is on the server side and content_restart() fails with a 500. As a workaround, this PR adds a tryCatch that will retry the request a single time if it gets a 500 error.

Closes #498

Checklist

  • Does this change update NEWS.md (referencing the connected issue if necessary)?
  • Does this change need documentation? Have you run devtools::document()?

@karawoo karawoo requested a review from a team February 13, 2026 00:25
R/content.R Outdated
Sys.sleep(1)
content$environment_set("{env_var_name}" := NA)
} else {
stop(e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine either way, but I wonder if this should be a warning rather than a stop? It is a bit of a funny error, but like we see here, the thing worked, it just hasn't totally cleaned itself up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, warning makes sense, I'll update it.

Copy link
Collaborator

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

I'm approving, but one comment of stop versus warning.

Also, given the server-state stuff httptest might be harder to use, but in other places I wonder if we could get away from maintaining this separate mock connect infrastructure and just lean into httptest — thoughts?

@karawoo
Copy link
Collaborator Author

karawoo commented Feb 13, 2026

Also, given the server-state stuff httptest might be harder to use, but in other places I wonder if we could get away from maintaining this separate mock connect infrastructure and just lean into httptest — thoughts?

To be honest I find the mock connect class way easier to work with and reason about than the httptest tests so I'm not terribly excited about that.

@karawoo karawoo merged commit 5325760 into main Feb 13, 2026
22 checks passed
@karawoo karawoo deleted the kara-restart-env-vars branch February 13, 2026 19:14
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.

Bug - content_restart() does not remove the env variable it sets

2 participants