mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 18:01:02 +00:00
added limit to streaming output to avoid crashes
This commit is contained in:
parent
97b3b96790
commit
73060a463c
2 changed files with 16 additions and 1 deletions
|
@ -395,7 +395,7 @@ func (b *Builder) run() error {
|
|||
|
||||
// attach to the container
|
||||
go func() {
|
||||
b.dockerClient.Containers.Attach(run.ID, &writer{b.Stdout})
|
||||
b.dockerClient.Containers.Attach(run.ID, &writer{b.Stdout, 0})
|
||||
}()
|
||||
|
||||
// start the container
|
||||
|
|
|
@ -12,12 +12,17 @@ var (
|
|||
// the prefix used to determine if this is
|
||||
// data that should be stripped from the output
|
||||
prefix = []byte("#DRONE:")
|
||||
|
||||
// default limit to use when streaming build output.
|
||||
DefaultLimit = 2000000
|
||||
)
|
||||
|
||||
// custom writer to intercept the build
|
||||
// output
|
||||
type writer struct {
|
||||
io.Writer
|
||||
|
||||
length int
|
||||
}
|
||||
|
||||
// Write appends the contents of p to the buffer. It will
|
||||
|
@ -25,6 +30,16 @@ type writer struct {
|
|||
// output, and will alter the output accordingly.
|
||||
func (w *writer) Write(p []byte) (n int, err error) {
|
||||
|
||||
// ensure we haven't exceeded the limit
|
||||
if w.length > DefaultLimit {
|
||||
w.Writer.Write([]byte("Truncating build output ..."))
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// track the number of bytes written to the
|
||||
// buffer so that we can limit it.
|
||||
w.length += len(p)
|
||||
|
||||
lines := strings.Split(string(p), "\n")
|
||||
for i, line := range lines {
|
||||
|
||||
|
|
Loading…
Reference in a new issue