Skip to content

go/types: deferred function executed multiple times #73267

Open
@adonovan

Description

@adonovan
#!stacks
"runtime.gopanic" &&
"types.(*Checker).handleBailout:+7" &&
 /* unfortunately there is no way to express bailout-within-bailout
     so we must subtract all other patterns that use bailout */
 !("go/types.setDefType:+7") // #71029

Issue created by stacks.

Well this is a weird one. Checker.Files. defers a function to recover from certain expected panics; that function re-panics for all other cases. However, the re-panic causes the deferred function to execute a second time (!). Presumably this means the defer bookkeeping (e.g. *_panic.deferBitsPtr) has become corrupted.

func (check *Checker) handleBailout(err *error) {
	switch p := recover().(type) {
	case nil, bailout:
		// normal return or early exit
		*err = check.firstErr
	default:
		// re-panic
		panic(p) <-- causes deferred call to check.handleBailout to execute again!
	}
}

// Files checks the provided files as part of the checker's package.
func (check *Checker) Files(files []*ast.File) (err error) {
...
	defer check.handleBailout(&err) <-- this closure is called repeatedly
	check.checkFiles(files)
	return
}

This stack k7voyQ was reported by telemetry:

golang.org/x/tools/[email protected] go1.23.7 darwin/arm64 other (2)

Dups: 5qvnIw UFUvMw

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.compiler/runtimeIssues related to the Go compiler and/or runtime.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions