Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gRPC: if an Upload request is canceled, immediately terminate the upload tool process. #2726

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 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed process termination when upload call is canceled
  • Loading branch information
cmaglie committed Oct 9, 2024
commit 5bbbe801ef44646776b2761a50edc62de9e40d5e
26 changes: 21 additions & 5 deletions 26 commands/service_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,18 @@ func (s *arduinoCoreServerImpl) runProgramAction(ctx context.Context, pme *packa
// Run recipes for upload
toolEnv := pme.GetEnvVarsForSpawnedProcess()
if burnBootloader {
if err := runTool("erase.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
if err := runTool(uploadCtx, "erase.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
return nil, &cmderrors.FailedUploadError{Message: i18n.Tr("Failed chip erase"), Cause: err}
}
if err := runTool("bootloader.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
if err := runTool(uploadCtx, "bootloader.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
return nil, &cmderrors.FailedUploadError{Message: i18n.Tr("Failed to burn bootloader"), Cause: err}
}
} else if programmer != nil {
if err := runTool("program.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
if err := runTool(uploadCtx, "program.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
return nil, &cmderrors.FailedUploadError{Message: i18n.Tr("Failed programming"), Cause: err}
}
} else {
if err := runTool("upload.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
if err := runTool(uploadCtx, "upload.pattern", uploadProperties, outStream, errStream, verbose, dryRun, toolEnv); err != nil {
return nil, &cmderrors.FailedUploadError{Message: i18n.Tr("Failed uploading"), Cause: err}
}
}
Expand Down Expand Up @@ -702,7 +702,12 @@ func detectUploadPort(
}
}

func runTool(recipeID string, props *properties.Map, outStream, errStream io.Writer, verbose bool, dryRun bool, toolEnv []string) error {
func runTool(ctx context.Context, recipeID string, props *properties.Map, outStream, errStream io.Writer, verbose bool, dryRun bool, toolEnv []string) error {
// if ctx is already canceled just exit
if err := ctx.Err(); err != nil {
return err
}

recipe, ok := props.GetOk(recipeID)
if !ok {
return errors.New(i18n.Tr("recipe not found '%s'", recipeID))
Expand Down Expand Up @@ -739,6 +744,17 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
return errors.New(i18n.Tr("cannot execute upload tool: %s", err))
}

// If the ctx is canceled, kill the running command
completed := make(chan struct{})
defer close(completed)
go func() {
select {
case <-ctx.Done():
_ = cmd.Kill()
case <-completed:
}
}()

if err := cmd.Wait(); err != nil {
return errors.New(i18n.Tr("uploading error: %s", err))
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.