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

fix(agent): Graceful Stop #3219

Merged
merged 2 commits into from
Oct 5, 2023
Merged

fix(agent): Graceful Stop #3219

merged 2 commits into from
Oct 5, 2023

Conversation

xoscar
Copy link
Contributor

@xoscar xoscar commented Oct 5, 2023

This PR fixes the problem when trying to stop the agent from the CLI option

Changes

  • Adds missing channel creation
  • Validates if the error is context stopped to not yield the errors to the console

Fixes

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

Loom video

https://www.loom.com/share/d0bf6ba20a074b16811e5524b20bb36f

@xoscar xoscar marked this pull request as ready for review October 5, 2023 18:28
@@ -138,3 +140,7 @@ func (c *Client) getName() (string, error) {

return hostname, nil
}

func isCancelledError(err error) bool {
Copy link
Contributor Author

@xoscar xoscar Oct 5, 2023

Choose a reason for hiding this comment

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

I didn't find a good way of doing this, the RPC message contains a wrapped error that when I tried to unwrap it was returning a plane interface{} object 🤷🏾

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try:

errors.Is(err, context.Canceled)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but it didn't work 😢

Comment on lines 30 to 32
if err != nil {
log.Fatal("could not get message from trigger stream: %w", err)
log.Fatal("could not get shutdown listener: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does forcing a shutdown here in case of an error make sense? Something like using: os.Exit(-1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe log.Fatal is already doing that

// Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatal(v ...any) {
	std.Output(2, fmt.Sprint(v...))
	os.Exit(1)
}

return
}

if err != nil {
log.Fatal("could not get message from trigger stream: %w", err)
log.Fatal("could not get message from ds connection stream: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Fatal("could not get message from ds connection stream: %w", err)
log.Fatal("could not get message from data store connection stream: %w", err)

@xoscar xoscar merged commit ecbbdcb into main Oct 5, 2023
@xoscar xoscar deleted the fix/agent-stop branch October 5, 2023 18:45
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