Make grpc_passthru_endpoint_stats refcounted#14236
Conversation
| gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC); | ||
|
|
||
| grpc_endpoint_pair MakeEndpoints(size_t kilobits) { | ||
| stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to |
There was a problem hiding this comment.
I'm not really proud of the way stats_ gets set as a side effect of MakeEndpoints, but I wanted to try if this fixes the flake first. Any ideas from a C++ expert here?
There was a problem hiding this comment.
I'll send a sub-PR, but I'm speculating that you want something based on shared_ptr, make_shared, shared_from_this, etc
There was a problem hiding this comment.
As discussed offline, I didn't use shared_ptr as passthru_endpoint.cc is under test/core and other files there doesn't use shared_ptr there yet either.
There was a problem hiding this comment.
Can I suggest doing it in the constructor instead of in MakeEndpoints? This basically should only be created once either way, and it makes sense to create it in the constructor since it gets destroyed in the destructor.
There was a problem hiding this comment.
Not sure I understand what you mean.
I need to pass MakeEndpoints to the base class constructor and in the body of this class' constructor it's too late for doing that.
- grpc_endpoint_pair is an "abstract" struct, so later extracting the stats from it (after EndpointPairFixture is constructed and knowing it's an passthru_endpoint) wouldn't work either.
There was a problem hiding this comment.
I think I solved it. PTAL.
|
|
| @@ -24,6 +24,7 @@ | |||
| #include "src/core/lib/iomgr/endpoint.h" | |||
|
|
|||
| typedef struct { | |||
There was a problem hiding this comment.
I did update all the places where grpc_passthru_endpoint_stats is used to use a pointer, but in theory nothing is preventing the struct to be used as a by-value field grpc_passthru_endpoint_stats stats_ in new code (which is presumably not good because of the refs). Perhaps a better encapsulation would be useful.
There was a problem hiding this comment.
This is test/core/util, so a comment putting that restriction in place should be sufficient.
There was a problem hiding this comment.
comment added.
|
|
This seems to be actually fixing the issue, I ran 5000 iterations locally and could not reproduce (I was able to reproduce before). |
| @@ -24,6 +24,7 @@ | |||
| #include "src/core/lib/iomgr/endpoint.h" | |||
|
|
|||
| typedef struct { | |||
There was a problem hiding this comment.
This is test/core/util, so a comment putting that restriction in place should be sufficient.
| gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC); | ||
|
|
||
| grpc_endpoint_pair MakeEndpoints(size_t kilobits) { | ||
| stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to |
There was a problem hiding this comment.
Can I suggest doing it in the constructor instead of in MakeEndpoints? This basically should only be created once either way, and it makes sense to create it in the constructor since it gets destroyed in the destructor.
|
|
I think I solved the problem with stats_ initialization and MakeEndpoints() being called before base constructor, I used a default parameter |
|
|
Fixed the problem with forbidden default arguments. PTAL. |
|
| gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC); | ||
|
|
||
| grpc_endpoint_pair MakeEndpoints(size_t kilobits) { | ||
| static grpc_endpoint_pair MakeEndpoints(size_t kilobits, |
There was a problem hiding this comment.
The static was a very nice touch to explicitly identify that this won't touch any member variables
|
|
|
Attempt to fix #13445.
Still needs some cleanup.