Skip to content
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

context: panic: interface conversion: interface {} is bool, not chan struct {} // #51789

Closed
gq0 opened this issue Mar 18, 2022 · 7 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@gq0
Copy link

gq0 commented Mar 18, 2022

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

$ go version
go version go1.17.8 linux/arm

Does this issue reproduce with the latest release?

It was not tested with 1.18 yet.

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

Linux 4.14.114 armv7l

What did you do?

We use the context to signal when to stop the goroutine in various places like shown below.

for {
  select {
    case <-ctx.Done():
	    return nil
    case .... 
  }
}

For a couple of months we randomly get on some of our IoT gateway in the field:

panic: interface conversion: interface {} is bool, not chan struct {}

At the point <-ctx.Done()

Sometimes, it is not a boolean but rather a value attached to the context. But we couldn't identify a pattern yet.

What did you expect to see?

No panic, instead signaling on the done channel.

Hint

I am not 100% but could it be that the done atomic.Value is not 64bit aligned? At least then, we might have issues with our 32bit arm architecture.
https://go-review.googlesource.com/c/go/+/288193/4/src/context/context.go#342

type cancelCtx struct {
	Context

	mu       sync.Mutex            // protects following fields
-->	done     atomic.Value          // of chan struct{}, created lazily, closed by first cancel call
	children map[canceler]struct{} // set to nil by the first cancel call
	err      error                 // set to non-nil by the first cancel call
}
@seankhliao
Copy link
Member

is there a full stacktrace?

@gq0
Copy link
Author

gq0 commented Mar 18, 2022

Yes

panic: interface conversion: interface {} is bool, not chan struct {}
goroutine 179 [running]:
context.(*cancelCtx).Done(0x28beab0)
/usr/local/go/src/context/context.go:361 +0x13c
github.com/grid-x/client/pkg/ioexchange.(*Mapper).Run(0x24a5f80, {0xb5a518, 0x28beab0})
/go/src/github.com/grid-x/client/pkg/ioexchange/mapper.go:80 +0xb4
main.main.func11(0x24a5f80, 0x26bce08, 0x280e070, 0x2498300)
/go/src/github.com/grid-x/client/cmd/monitoring/main.go:614 +0x30
created by main.main

@mvdan
Copy link
Member

mvdan commented Mar 18, 2022

@gq0 have you tried reproducing with -race? Sometimes this kind of bug can be caused by memory corruption due to data races.

@gq0
Copy link
Author

gq0 commented Mar 18, 2022

No, not yet. It takes some time to occur and not on all systems. But we give it a try. I think -race is also not available for arm build in 1.17

Regarding the cancelCtx type is my assumption right on a 32bit system?

type cancelCtx struct {
	Context                        // 32 bit, is this right on armv7?
	mu       sync.Mutex            // 64 bit
-->	done     atomic.Value          // not 64 bit aligned?
      ....
}

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 18, 2022
@ianlancetaylor
Copy link
Contributor

It's OK if atomic.Value is not aligned on a 64-bit boundary. The implementation of atomic.Value only does 32-bit atomic accesses on a 32-bit system.

What is not OK is using atomic.LoadInt64 and friends on a misaligned int64 on a 32-bit system. But atomic.Value doesn't do that.

@gq0
Copy link
Author

gq0 commented Mar 18, 2022

@ianlancetaylor, thanks for the clarification 👍🏻

@gq0
Copy link
Author

gq0 commented Apr 19, 2022

It was an issue related to the passing of the context to a goroutine and wrapping of it later, similar buildkite/agent#1606

@gq0 gq0 closed this as completed Apr 19, 2022
@golang golang locked and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants