Skip to content

Men 8382 mender artifact fails on calling mender update show provides #703

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michalkopczan
Copy link

New PR, disregard the old one (701)
Added two separate commits, one for the fix, another for ssh refactoring.
Compared to previous version, I removed fixes for restoring echo and hanging ssh in case remote device fails silently (e.g. power loss). Will move it to new tasks.

…sudo and properly handle sudo asking for password.

Changelog: Title
Ticket: MEN-8382

Signed-off-by: Michal Kopczan <michal.kopczan@northern.tech>
…ove it to cli/utils/ssh.go

Changelog: None
Ticket: MEN-8382

Signed-off-by: Michal Kopczan <michal.kopczan@northern.tech>
@mender-test-bot
Copy link

@michalkopczan, start a full client pipeline with:

  • mentioning me and `start client pipeline"start client pipeline".

my commands and options

You can prevent me from automatically starting CI pipelines:

  • if your pull request title starts with "[NoCI] ..."

You can trigger a client pipeline on multiple prs with:

  • mentioning me and start client pipeline --pr mender/127 --pr mender-connect/255

You can trigger GitHub->GitLab branch sync with:

  • mentioning me and sync

You can cherry pick to a given branch or branches with:

  • mentioning me and:
 cherry-pick to:
 * 1.0.x
 * 2.0.x

Copy link
Contributor

@vpodzime vpodzime left a comment

Choose a reason for hiding this comment

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

Looks generally good to me, but I cannot assess the quality of the Go code due to lack of knowledge/experience. @alfrunes please help. :)

cli/write.go Outdated
return nil, nil

// Wait for 60 seconds for ssh to establish connection
err = waitForBufferSignal(stdout, os.Stdout, sshInitMagic, 2*time.Minute)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like 2 minutes and thus 120 seconds to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the comment should say 120 seconds instead

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@danielskinstad danielskinstad left a comment

Choose a reason for hiding this comment

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

Again, I think the code looks good :)

This is perhaps a personal preference, feel free to dismiss, but personally I would prefer a bit shorter commit titles and rather do something like:
fix: call show-provides with sudo
Changelog: Fix crash when generating artifact from ssh by adding sudo to show-provides and properly handle sudo asking for password

cli/write.go Outdated
Comment on lines 1039 to 1048
if err == nil {
sigChan = make(chan os.Signal, 1)
errChan = make(chan error, 1)
// Make sure that echo is enabled if the process gets
// interrupted
signal.Notify(sigChan)
go util.EchoSigHandler(ctx, sigChan, errChan, term)
} else if err != syscall.ENOTTY {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we intentionally ignoring all errors except ENOTTY?

Copy link
Author

Choose a reason for hiding this comment

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

Huh, it also caught me by surprise - that's exactly what I though when I first saw this code (it was there before, I just moved it to new file). But this is not the case. Actually, we're ignoring ENOTTY exclusively.

  • if there's no error, we set up echoSigHandler to re enable echo on signal
  • if there's any error except ENOTTY, we return an error
  • if there's ENOTTY error, we ignore it, because there's no need to disable echo if there's no TTY


type SSHCommand struct {
Cmd *exec.Cmd
ctx context.Context
Copy link
Contributor

Choose a reason for hiding this comment

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

The ctx is unused.

Suggested change
ctx context.Context

Side-note; storing Context in structs is in most cases considered an anti-pattern in Go

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the tip about anti-pattern.
I thought that by adding ctx here even though it's unused, I am making sure that the context lives long enough to be used in EchoSigHandler. Now I understand this is wrong.
Can you confirm that supplying _ctx to EchoSigHandler makes sure that the lifetime is extended so that EchoSigHandler can handle it every time, even if the app is being closed?

Comment on lines +179 to +180
case <-time.After(deadline):
err = errors.New("Input deadline exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also reuse the deadline from the context in the parent scope here instead of a fixed duration.

Suggested change
case <-time.After(deadline):
err = errors.New("Input deadline exceeded")
case <-ctx.Done():
err = ctx.Err()

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure I understand, sorry - new to Go and new to the code above (just moved, not written myself)
Do you mean to reuse context as in, "if the execution finished, context was marked as Done, we return an error in waitForBufferSignal"?
My understanding here is that we wait either for error, or for 120 seconds for user to provide a root password over ssh. If user does not provide a password within 120 seconds, we return an error. I don't understand how reusing context could be used here.

Changelog: Fix crash when generating artifact from ssh by adding sudo to show-provides and properly handle sudo asking for password
Ticket: MEN-8382

Signed-off-by: Michal Kopczan <michal.kopczan@northern.tech>
@mender-test-bot
Copy link

mender-test-bot commented Jun 2, 2025

Merging these commits will result in the following changelog entries:

Changelogs

mender-artifact (MEN-8382_new-mender-artifact_fails_on_calling_mender-update_show-provides)

New changes in mender-artifact since master:

Bug Fixes
  • Fix crash when generating artifact from ssh by adding sudo to show-provides and properly handle sudo asking for password
    (MEN-8382)
  • Fix mender-artifact crash on generating artifact from ssh - add sudo and properly handle sudo asking for password.
    (MEN-8382)

@mender-test-bot
Copy link

@michalkopczan, start a full client pipeline with:

  • mentioning me and start client pipeline

my commands and options

You can prevent me from automatically starting CI pipelines:

  • if your pull request title starts with "[NoCI] ..."

You can trigger a client pipeline on multiple prs with:

  • mentioning me and start client pipeline --pr mender/127 --pr mender-connect/255

You can trigger GitHub->GitLab branch sync with:

  • mentioning me and sync

You can cherry pick to a given branch or branches with:

  • mentioning me and:
 cherry-pick to:
 * 1.0.x
 * 2.0.x

@michalkopczan
Copy link
Author

Added new commit, with format suggested by Daniel. I'll rewrite the commits after the review is finished to comply with our guidelines, i.e. two commits - one for fix, one for refactoring.

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.

5 participants