grpcsync: add ScheduleAndWait to CallbackSerializer#8998
grpcsync: add ScheduleAndWait to CallbackSerializer#8998Retr0-XD wants to merge 8 commits intogrpc:masterfrom
Conversation
Introduces ScheduleAndWait, which schedules a callback on the CallbackSerializer and blocks until it has been executed. Returns nil on success, or ErrSerializerClosed if the serializer was already shut down at the time of the call. This replaces a common pattern where callers create a done channel, close it inside the scheduled callback, and then block on it. Fixes grpc#8501
|
@Pranjali-2501 can you please review this PR :) |
|
@Retr0-XD , CI is failing. Please fix it. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8998 +/- ##
==========================================
- Coverage 83.04% 83.00% -0.05%
==========================================
Files 411 411
Lines 32892 32969 +77
==========================================
+ Hits 27316 27365 +49
- Misses 4181 4200 +19
- Partials 1395 1404 +9
🚀 New features to boost your workflow:
|
|
Hi @Pranjali-2501 , CI fixed , the label is missing for PR validation check alone . Please review and let me know. |
|
Let me know if anything else is required |
| f(ctx) | ||
| close(done) | ||
| }) != nil { | ||
| return ErrSerializerClosed |
There was a problem hiding this comment.
What is the purpose of returning this new error sentinel given that this can fail only when the caller of this method cancels the context that they themselves passed to this method? Why not just return the error returned from Put as is.
|
Also, can you please merge master into your branch. That should take care of the failing vet-proto CI. |
| mu sync.Mutex | ||
| counter int |
There was a problem hiding this comment.
Nit: Can we use an atomic.Int instead?
|
|
||
| for i := 0; i < numCallbacks; i++ { | ||
| go func() { | ||
| defer wg.Done() |
There was a problem hiding this comment.
Could you consider using WaitGroup.Go. This is the new ergonomic way of spawning goroutines and waiting on them to complete with a WaitGroup.
Description
Adds a
ScheduleAndWaitmethod toCallbackSerializerthat schedules a callback and blocks until it has been executed.This eliminates a repetitive pattern scattered throughout the codebase where callers create a
donechannel, close it inside the callback, and block on it:API
Tests added
TestCallbackSerializer_ScheduleAndWait_Normal— happy path: callback executes and returns nilTestCallbackSerializer_ScheduleAndWait_Closed— serializer already shut down: returnsErrSerializerClosedTestCallbackSerializer_ScheduleAndWait_FIFO— FIFO ordering is preserved relative toTryScheduleTestCallbackSerializer_ScheduleAndWait_Concurrent— 50 concurrent callers all complete successfullyRELEASE NOTES:
Fixes #8501
AI disclosure: GitHub Copilot was used during implementation and test writing. I fully understand all changes made in this PR.