Description
TIL that time.Timer is not what it seems: it looks like a struct with two fields, but it is in fact the tip of an iceberg of a runtime data structure, timeTimer, that is much larger. So long as you create a Timer using NewTimer (as is required), all is well, but if you call methods on a Timer that you have (foolishly) created yourself, then the runtime will look for its submerged part of the iceberg, and instead find... whatever is adjacent in the heap.
There's an open issue (#69186) against cmd/vet to report this, but I wonder whether a more robust change would be to declare time.Timer so that it has the same shape as the runtime timeTimer (with a bunch of blank int and pointer fields) to avoid this particular kind of corruption.
(The initTimer bool
field would need to be replaced by a self-pointer, so that copying a Timer doesn't copy the "initialized" state: a copy of a self-pointer is no longer a self-pointer.)
cc: @prattmic @golang/runtime
Metadata
Metadata
Assignees
Labels
Type
Projects
Status