interfaceHash reads too far into data
anacrolix opened this issue · comments
Matt Joiner commented
interfaceHash
calls fmt.Sprintf("%v", x)
which can cause it to read into mutable data triggering the race detector. The hashing used by Go's built-in map
key types would be more appropriate (for instance pointer types would just use a hash of the pointer value). I tried to implement this using Go's internal interhash
, but it just triggers nil
deference errors that I couldn't figure out.
Matt Joiner commented
Here's how I tried to use interhash
: anacrolix@70355c2
Tobias Gustafsson commented
Hi,
Great thinking! I think the problem was that it is an empty interface,
which is a special case in the runtime. So, you need to use
nilinterhash instead.
See
https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#the-empty-interface
I pushed a new commit on master with the update:
80d0820
Please let me know what the race detector thinks.
Thanks!
// Tobias
Den fre 25 okt. 2019 kl 02:42 skrev Matt Joiner <notifications@github.com>:
… Here's how I tried to use interhash: ***@***.***
<anacrolix@70355c2>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#7?email_source=notifications&email_token=AADWTTEG6VZYKKOUBBTLFK3QQI6HVA5CNFSM4JE5DEBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECG2TQI#issuecomment-546154945>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADWTTEFBDL5B2AFLAFTRHLQQI6HVANCNFSM4JE5DEBA>
.
Matt Joiner commented
The race detector seems happy, and all my tests are passing. I'm not sure why it needed to handle the nil
case.
Tobias Gustafsson commented
I think the problem is that eface does not have the tab element that is
present on iface so interhash would crash on line 142 here:
https://golang.org/src/runtime/alg.go
Den fre 25 okt. 2019 kl 12:29 skrev Matt Joiner <notifications@github.com>:
… The race detector seems happy, and all my tests are passing. I'm not sure
why it needed to handle the nil case.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7?email_source=notifications&email_token=AADWTTEXPWIHDH2TTWXAAH3QQLDABA5CNFSM4JE5DEBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECH52WA#issuecomment-546299224>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADWTTGJHEQWWEX2I2MF5W3QQLDABANCNFSM4JE5DEBA>
.
Matt Joiner commented
Fantastic, thanks!