Skip to content

fix(agent/agentscripts): display informative error for ErrWaitDelay #10407

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

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Oct 27, 2023

This PR makes it so that Coder shows an informative error instead of exec.ErrWaitDelay to users. To ease with discovery, and informing the user that something is wrong, the message is printed to both the script log (db/file) and to the agent log.

Fixes #10400

Web UI example:
image

Agent log example:

2023-10-27 11:53:35.129 [debu]  sdk response  method=POST  url=http://host.docker.internal:3000/api/v2/workspaceagents/me/metadata  status=204  body=""  trace_id=""  span_id=""
2023-10-27 11:53:35.817 [warn]  script exited successfully, but output pipes were not closed after 10s  details="This usually means a child process was started with references to stdout or stderr. As a result, this
 process may now have been terminated. Consider redirecting the output or using a separate \"coder_script\" for the process, see https://coder.com/docs/v2/latest/templates/troubleshooting#startup-script-issues for more information." ...
    error= script exited without closing output pipes:
               github.com/coder/coder/v2/agent/agentscripts.init
                   /home/coder/src/coder/coder/agent/agentscripts/agentscripts.go:31
2023-10-27 11:53:35.817 [warn]  /tmp/coder-startup-script.log script failed  log_path=/tmp/coder-startup-script.log  execution_time=13.665894534s  exit_code=255 ...
    error= script exited without closing output pipes:
               github.com/coder/coder/v2/agent/agentscripts.init
                   /home/coder/src/coder/coder/agent/agentscripts/agentscripts.go:31
2023-10-27 11:53:35.817 [debu]  sdk request  method=PATCH  url=http://host.docker.internal:3000/api/v2/workspaceagents/me/logs  body=""
2023-10-27 11:53:35.826 [debu]  sdk response  method=PATCH  url=http://host.docker.internal:3000/api/v2/workspaceagents/me/logs  status=200  body=""  trace_id=""  span_id=""
2023-10-27 11:53:35.826 [debu]  startup logs sender exited  log_path=/tmp/coder-startup-script.log
2023-10-27 11:53:35.826 [warn]  startup script(s) failed ...
    error= run agent script "5d6eb345-a901-4c07-8ca2-79331a0c3699":
               github.com/coder/coder/v2/agent/agentscripts.(*Runner).Execute.func2
                   /home/coder/src/coder/coder/agent/agentscripts/agentscripts.go:130
             - script exited without closing output pipes:
               github.com/coder/coder/v2/agent/agentscripts.init
                   /home/coder/src/coder/coder/agent/agentscripts/agentscripts.go:31
2023-10-27 11:53:35.826 [debu]  set lifecycle state  current={"state":"start_error","changed_at":"2023-10-27T11:53:35.826803Z"}  last={"state":"starting","changed_at":"2023-10-27T11:53:22.150913Z"}
2023-10-27 11:53:35.826 [debu]  reporting lifecycle state  payload={"state":"start_error","changed_at":"2023-10-27T11:53:35.826803Z"}

@mafredri mafredri requested a review from kylecarbs October 27, 2023 12:01
@mafredri mafredri changed the title fix(agent/agentscripts): show informative error for ErrWaitDelay fix(agent/agentscripts): display informative error for ErrWaitDelay Oct 27, 2023
@mafredri mafredri force-pushed the mafredri/fix-agentscripts-informative-pipe-error branch from a5479a8 to 3b4be86 Compare October 27, 2023 12:39
@matifali
Copy link
Member

Offtopic: Do you know why lines 31, 32, etc, are misaligned in the screenshot?

@mafredri
Copy link
Member Author

Offtopic: Do you know why lines 31, 32, etc, are misaligned in the screenshot?

I've reported it here: #10176

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

An absolutely fantastic change!

@mafredri mafredri merged commit 7fecd39 into main Oct 27, 2023
@mafredri mafredri deleted the mafredri/fix-agentscripts-informative-pipe-error branch October 27, 2023 16:07
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coder scripts exit the following error: exec: WaitDelay expired before I/O complete
3 participants