René's URL Explorer Experiment


Title: bug: agent hangs on shutdown when a cron script is running (deadlock in agentscripts.Runner.Close) · Issue #32461 · coder/coder · GitHub

Open Graph Title: bug: agent hangs on shutdown when a cron script is running (deadlock in agentscripts.Runner.Close) · Issue #32461 · coder/coder

X Title: bug: agent hangs on shutdown when a cron script is running (deadlock in agentscripts.Runner.Close) · Issue #32461 · coder/coder

Description: Is there an existing issue for this? I have searched the existing issues Current Behavior If a workspace stops while a coder_script with cron set is still running, the agent never finishes shutting down. On SIGTERM the agent process keep...

Open Graph Description: Is there an existing issue for this? I have searched the existing issues Current Behavior If a workspace stops while a coder_script with cron set is still running, the agent never finishes shutting...

X Description: Is there an existing issue for this? I have searched the existing issues Current Behavior If a workspace stops while a coder_script with cron set is still running, the agent never finishes shutting...

Opengraph URL: https://github.com/coder/coder/issues/32461

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: agent hangs on shutdown when a cron script is running (deadlock in agentscripts.Runner.Close)","articleBody":"### Is there an existing issue for this?\n\n- [x] I have searched the existing issues\n\n### Current Behavior\n\nIf a workspace stops while a `coder_script` with `cron` set is still running, the agent never finishes shutting down. On SIGTERM the agent process keeps running until it is killed. On Kubernetes the pod stays in `Terminating` for the full `terminationGracePeriodSeconds` and then gets SIGKILLed. Shutdowns that happen while no cron run is in progress finish normally.\n\nThe cause is a lock-ordering deadlock in `Runner.Close()` in [`agent/agentscripts/agentscripts.go`](https://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L553-L575):\n\n1. `Close()` sets `closing`, releases `closeMutex`, and waits on `executeWait` with the mutex released. The comment there explains why: in-flight `Execute` calls report timings through `trackCommandGoroutine`, which takes `closeMutex`.\n2. It then takes `closeMutex` again with `defer Unlock()`, closes `r.closed`, cancels the cron context, and blocks on `\u003c-r.cron.Stop().Done()` ([L571](https://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L571)) **while still holding the mutex**.\n3. `cron.Stop()` waits for running jobs. The cron script that is in flight is cancelled, and when its command returns, `run()` reports the timing through `r.trackCommandGoroutine(...)` ([L456](https://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L456)), which blocks on `closeMutex`.\n\nThe cron job never returns, so `cron.Stop()` never finishes and `Close()` never returns.\n\n### Relevant Log Output\n\n```shell\n# goroutine dump of the unfixed code at the commit above, taken while Close() hangs (runtime frames trimmed)\ngoroutine 39 [chan receive]:\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).Close(...)\n\tagent/agentscripts/agentscripts.go:571\n\ngoroutine 90 [sync.Mutex.Lock]:\nsync.(*Mutex).Lock(...)\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).trackCommandGoroutine(...)\n\tagent/agentscripts/agentscripts.go:577\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).run.func3()\n\tagent/agentscripts/agentscripts.go:456\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).run(...)\n\tagent/agentscripts/agentscripts.go:547\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).trackRun(...)\n\tagent/agentscripts/agentscripts.go:323\ngithub.com/coder/coder/v2/agent/agentscripts.(*Runner).Init.func1()\n\tagent/agentscripts/agentscripts.go:165\ngithub.com/robfig/cron/v3.FuncJob.Run(...)\ngithub.com/robfig/cron/v3.(*Cron).startJob.func1()\n```\n\n### Expected Behavior\n\n`Close()` cancels the in-flight cron run, waits for it, and returns. `trackCommandGoroutine` should see that the runner is closed and return an error instead of blocking, which is what already happens for in-flight `Execute` calls.\n\n### Steps to Reproduce\n\n1. Use a template with a `coder_script` that runs on a schedule and takes a few seconds, for example:\n   ```hcl\n   resource \"coder_script\" \"periodic\" {\n     agent_id     = coder_agent.main.id\n     display_name = \"periodic\"\n     cron         = \"*/30 * * * * *\"\n     script       = \"sleep 20\"\n   }\n   ```\n2. Start the workspace and wait for the script to start a run.\n3. Stop the workspace (or send SIGTERM to the agent) while the run is in progress.\n4. The agent does not exit until it is force-killed.\n\nMinimal Go reproduction in `agent/agentscripts`: `Init` with one script whose `Cron` is `\"* * * * * *\"` and whose command sleeps, call `StartCron()`, wait for the script to start, then call `Close()`. `Close()` never returns.\n\n### Environment\n\n- Host OS: Linux (Kubernetes)\n- Coder version: v2.39.4; also reproduced on `main` at 5f61a045ab6c50b93603b520fea62f2911ac232a\n\n### Additional Context\n\nThe issue occurs consistently, I have tested this on the latest version\n\nI have a fix with a regression test ready and will open a PR shortly.\n","author":{"url":"https://github.com/simonepri","@type":"Person","name":"simonepri"},"datePublished":"2026-11-19T17:12:35Z","url":"https://github.com/coder/coder/issues/32461"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:4581edfa-2c62-7b31-004f-0dc38ce02248
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBCAE:176DDE:1BDEAC:2572EA:6B043098
html-safe-nonce446af3227cd67bd392f1790010537df78c7f6f4c6d3f392079d1c77d2f52af10
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0FFOjE3NkRERToxQkRFQUM6MjU3MkVBOjZCMDQzMDk4IiwidmlzaXRvcl9pZCI6IjY4NzM0ODU2NDMwNTQ1OTIxNTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac775924c74ede9772a221be18c0219e9f150867fb2bfb25a9f677d01562c5345e
hovercard-subject-tagissue:6495038264
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/32461/issue_layout
twitter:imagehttps://opengraph.githubassets.com/71695a2af68df6bf4c33d238ce2fca3b59f201e55046d33e010f23bd48a2816c/coder/coder/issues/32461
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/71695a2af68df6bf4c33d238ce2fca3b59f201e55046d33e010f23bd48a2816c/coder/coder/issues/32461
og:image:altIs there an existing issue for this? I have searched the existing issues Current Behavior If a workspace stops while a coder_script with cron set is still running, the agent never finishes shutting...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesimonepri
hostnamegithub.com
expected-hostnamegithub.com
Noneb7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e
turbo-cache-controlno-preview
go-importgithub.com/coder/coder git https://github.com/coder/coder.git
octolytics-dimension-user_id95932066
octolytics-dimension-user_logincoder
octolytics-dimension-repository_id440752086
octolytics-dimension-repository_nwocoder/coder
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id440752086
octolytics-dimension-repository_network_root_nwocoder/coder
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec3dd496c3da6ea6b77e69c09279d2b81604654f1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/coder/coder/issues/32461#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcoder%2Fissues%2F32461
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fcoder%2Fissues%2F32461
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=coder%2Fcoder
Reloadhttps://github.com/coder/coder/issues/32461
Reloadhttps://github.com/coder/coder/issues/32461
Reloadhttps://github.com/coder/coder/issues/32461
coderhttps://github.com/coder
coderhttps://github.com/coder/coder
Codehttps://github.com/coder/coder
Issues322 (322)https://github.com/coder/coder/issues
Pull requests472 (472)https://github.com/coder/coder/pulls
Discussionshttps://github.com/coder/coder/discussions
Actionshttps://github.com/coder/coder/actions
Projectshttps://github.com/coder/coder/projects
Security and quality49 (49)https://github.com/coder/coder/security
Insightshttps://github.com/coder/coder/insights
https://github.com/coder/coder
New issuehttps://github.com/login?return_to=https://github.com/coder/coder/issues/32461
New issuehttps://github.com/login?return_to=https://github.com/coder/coder/issues/32461
#32462https://github.com/coder/coder/pull/32462
bug: agent hangs on shutdown when a cron script is running (deadlock in agentscripts.Runner.Close)https://github.com/coder/coder/issues/32461#top
#32462https://github.com/coder/coder/pull/32462
https://github.com/simonepri
simoneprihttps://github.com/simonepri
on Nov 19, 2026https://github.com/coder/coder/issues/32461#issue-6495038264
agent/agentscripts/agentscripts.gohttps://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L553-L575
L571https://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L571
L456https://github.com/coder/coder/blob/5f61a045ab6c50b93603b520fea62f2911ac232a/agent/agentscripts/agentscripts.go#L456
5f61a04https://github.com/coder/coder/commit/5f61a045ab6c50b93603b520fea62f2911ac232a
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Nov 19, 2026https://github.com/coder/coder/issues/32461#issuecomment-7016380343
Linear Codehttps://linear.app
ENG-3552https://linear.app/codercom/issue/ENG-3552
Sign up for freehttps://github.com/signup?return_to=https://github.com/coder/coder/issues/32461
Sign in to commenthttps://github.com/login?return_to=https://github.com/coder/coder/issues/32461
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.