grpc/grpc-swift

pool.id uses `ObjectIdentifier(connection)` as the ID but that's not unique.

weissi opened this issue · 4 comments

ObjectIdentifier(something) is not unique. It's only unique at any given point in time. But it is not unique across the lifetime of a program. It prints the allocation address and after freeing one object, it will be available again to the next.

For example see how each of the 100 Class() instances has the same address/ObjectIdentifier

$ echo 'class Clazz {}; for _ in 0..<100 { print(ObjectIdentifier(Clazz())) }' | swift - | sort | uniq -c
 100 ObjectIdentifier(0x0000600000860bd0)

Point taken but for the connection pool I think it's okay: each sub-pool (i.e. the thing we're identifying) is guaranteed lives for as long as the pool so they will be unique.

Point taken but for the connection pool I think it's okay: each sub-pool (i.e. the thing we're identifying) is guaranteed lives for as long as the pool so they will be unique.

What if the pool shuts down?

Also, the current ID wastes a lot of characters for nothing. I think a simple atomic counter like NIO/AHC do is better. Or UUID if you want globally unique.

I'm not disagreeing with the premise of the issue. It's just low priority as pools are typically long-lived so IDs should be unique enough.

Ended up doing this as part of #1852