Skip to content

bugfix: Kill compile processes that generates too much output #2883

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 4 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
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
Next Next commit
Added integration test
  • Loading branch information
cmaglie committed May 12, 2025
commit 0a634d63c46a08377bf79215bc40454468e77f97
19 changes: 15 additions & 4 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) {
return cli.RunWithCustomEnv(cli.cliEnvVars, args...)
}

// RunWithContext executes the given arduino-cli command with the given context and returns the output.
// If the context is canceled, the command is killed.
func (cli *ArduinoCLI) RunWithContext(ctx context.Context, args ...string) ([]byte, []byte, error) {
return cli.RunWithCustomEnvContext(ctx, cli.cliEnvVars, args...)
}

// GetDefaultEnv returns a copy of the default execution env used with the Run method.
func (cli *ArduinoCLI) GetDefaultEnv() map[string]string {
res := map[string]string{}
Expand Down Expand Up @@ -324,8 +330,13 @@ func (cli *ArduinoCLI) InstallMockedAvrdude(t *testing.T) {

// RunWithCustomEnv executes the given arduino-cli command with the given custom env and returns the output.
func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) ([]byte, []byte, error) {
return cli.RunWithCustomEnvContext(context.Background(), env, args...)
}

// RunWithCustomEnv executes the given arduino-cli command with the given custom env and returns the output.
func (cli *ArduinoCLI) RunWithCustomEnvContext(ctx context.Context, env map[string]string, args ...string) ([]byte, []byte, error) {
var stdoutBuf, stderrBuf bytes.Buffer
err := cli.run(&stdoutBuf, &stderrBuf, nil, env, args...)
err := cli.run(ctx, &stdoutBuf, &stderrBuf, nil, env, args...)

errBuf := stderrBuf.Bytes()
cli.t.NotContains(string(errBuf), "panic: runtime error:", "arduino-cli panicked")
Expand All @@ -336,15 +347,15 @@ func (cli *ArduinoCLI) RunWithCustomEnv(env map[string]string, args ...string) (
// RunWithCustomInput executes the given arduino-cli command pushing the given input stream and returns the output.
func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte, []byte, error) {
var stdoutBuf, stderrBuf bytes.Buffer
err := cli.run(&stdoutBuf, &stderrBuf, in, cli.cliEnvVars, args...)
err := cli.run(context.Background(), &stdoutBuf, &stderrBuf, in, cli.cliEnvVars, args...)

errBuf := stderrBuf.Bytes()
cli.t.NotContains(string(errBuf), "panic: runtime error:", "arduino-cli panicked")

return stdoutBuf.Bytes(), errBuf, err
}

func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) error {
func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader, env map[string]string, args ...string) error {
if cli.cliConfigPath != nil {
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
}
Expand Down Expand Up @@ -402,8 +413,8 @@ func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader
}
}()
}
cliErr := cliProc.WaitWithinContext(ctx)
wg.Wait()
cliErr := cliProc.Wait()
fmt.Fprintln(terminalOut, color.HiBlackString("<<< Run completed (err = %v)", cliErr))

return cliErr
Expand Down
44 changes: 44 additions & 0 deletions internal/integrationtest/compile_5/recusive_include_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This file is part of arduino-cli.
//
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package compile_test

import (
"context"
"testing"
"time"

"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)

func TestCompileWithInfiniteMultipleIncludeRecursion(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
t.Cleanup(env.CleanUp)

// Install Arduino AVR Boards
_, _, err := cli.Run("core", "install", "arduino:avr@1.8.6")
require.NoError(t, err)

sketch, err := paths.New("testdata", "SketchWithRecursiveIncludes").Abs()
require.NoError(t, err)

// Time-limited test to prevent OOM
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
t.Cleanup(cancel)
_, _, _ = cli.RunWithContext(ctx, "compile", "-b", "arduino:avr:uno", sketch.String())
require.NotErrorIs(t, ctx.Err(), context.DeadlineExceeded, "compilation should not hang")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "a.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "a.h"
#include "a.h"
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy