Skip to content

testing: call (*M).after on signal or internal-generated panic #19394

Closed

Description

@codesenberg

What version of Go are you using (go version)?

go version go1.8 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\frei\Documents\Go\Workspaces\Default
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\frei\AppData\Local\Temp\go-build564910375=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

Ran go test -cpuprofile cpu.pprof -memprofile mem.pprof -timeout 10s in a folder with the following test file:

package main

import (
	"flag"
	"runtime"
	"testing"
	"time"
)

var (
	testDuration = flag.Duration(
		"duration", 30*time.Second, "how long to run tests",
	)
	workers = flag.Uint("workers", 10, "number of workers")
)

func TestDummy(t *testing.T) {
	for i := uint(0); i < *workers; i++ {
		go func() {
			counter := 0
			for {
				counter++
				runtime.Gosched()
			}
		}()
	}
	time.Sleep(*testDuration)
}

What did you expect to see?

Tests to end with a panic and non-empty profiles in cpu.pprof and mem.pprof.

What did you see instead?

Tests ended with a panic, but cpu.pprof was empty and mem.pprof wasn't created at all.

Previous discussion on #golang-nuts: link.

/cc @ianlancetaylor

Activity

  1. changed the title [-]testing: -cpuprofile and -memprofile produce empty profiles or no profile at all, when tests end with a panic, because of a timeout[/-] [+]testing: -cpuprofile and -memprofile produce empty profile or no profile at all, when tests end with a panic, because of a timeout[/+] on Mar 4, 2017
  2. added this to the Go1.9 milestone on Mar 4, 2017
  3. ALTree commented on Mar 4, 2017

    @ALTree
    Member

    As I see it, running with a timeout set means "this shouldn't take more than 10 seconds, abort the program if it does". It's not meant to be used as a knob to control benchmarking duration; and you shouldn't use it this way. Your program was aborted because you started it with a flag set that means: "this should never take more than 10 seconds, please panic if it does".

    So the question here is: should we guarantee that partial profiles are written to file if the program is killed/aborted because an invalid condition / unrecoverable problem occurred?

    I don't think we should.

  4. josharian commented on Mar 4, 2017

    @josharian
    Contributor

    The reason I would like to write partial profiles if the program is killed (at least internally) is that sometimes I start a large benchmarking run (e.g. math/big with -count=20) and forget to bump up the timeout, and the test gets killed, and I lose 10 minutes worth of profiling efforts.

  5. ALTree commented on Mar 4, 2017

    @ALTree
    Member

    @josharian to solve that problem maybe we could ignore the default timeout value (10m) when go test detects we're running benchmarks. Or make -count N multiply the timeout by N.

  6. randall77 commented on Mar 4, 2017

    @randall77
    Contributor

    I've been bitten by this before. Having -count N multiply the timeout by N sounds like a good fix.

  7. codesenberg commented on Mar 4, 2017

    @codesenberg
    ContributorAuthor

    @ALTree, nah, this program is just for the ease of reproduction. I discovered this issue in a context unrelated to benchmarking and thought that I should report it. How you resolve it is up to you guys. I, personally, would like to see that "partial" profile, because of the time wasted. Also, maybe, those profiles could help to resolve the issues with the code that led to this timeout. Just my 2 cents.

  8. josharian commented on Apr 10, 2017

    @josharian
    Contributor

    Related: #12446. This just bit me again. The fix appears to be trivial: add *timeout *= len(cpuList) to the end of parseCpuList. But documenting it got hard, and I started worrying about whether anyone might really depend on -timeout being a hard timeout. Thoughts?

  9. ALTree commented on Jun 6, 2017

    @ALTree
    Member

    We're deep in the freeze with no consensus about what should be done and no CL implementing generation of partial profiles, so I'm moving this to the go1.10 milestone.

  10. modified the milestones: Go1.10, Go1.9 on Jun 6, 2017
  11. added
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Jun 6, 2017
  12. rsc commented on Jun 26, 2017

    @rsc
    Contributor

    I don't see how to fix this without adding atexit, which we've worked hard to avoid.

  13. rsc commented on Jun 26, 2017

    @rsc
    Contributor

    I see the argument for multiplying timeout by count but on the other hand -count=100 turning into 1000m timeout might not be what you want.

  14. rsc commented on Jun 26, 2017

    @rsc
    Contributor

    If we only care about the specific case of a signal arriving, or the internal panic generated by a timeout - that is, the intersection of the two things I just replied to - then we could arrange to call m.after() carefully ourselves before exiting. That seems OK to try at least if anyone is interested in preparing a CL.

  15. changed the title [-]testing: -cpuprofile and -memprofile produce empty profile or no profile at all, when tests end with a panic, because of a timeout[/-] [+]testing: call (*M).after on signal or internal-generated panic[/+] on Jun 26, 2017
  16. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Jun 26, 2017
  17. gopherbot commented on Jul 14, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/48491 mentions this issue.

  18. meirf commented on Aug 28, 2017

    @meirf
    Contributor

    My fix was only partial but bot closed this. I used Fixes in CL, which was probably the wrong thing to do.

  19. locked and limited conversation to collaborators on Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions