-
Notifications
You must be signed in to change notification settings - Fork 62
replace errgroup with conc pool in WriteExecute method #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughReplaces per-chunk parallel execution from an errgroup-based approach to a pool-based concurrency model in the Go client template. Introduces controlled worker pools with context propagation, refactors authentication error handling via Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant OldErrGroup as Old: ErrGroup
participant NewPool as New: Worker Pool
participant Chunk
Client->>OldErrGroup: WriteExecute(chunks)
loop Per Chunk (indexed)
OldErrGroup->>Chunk: Go(i) → execute chunk[i]
Chunk-->>OldErrGroup: response
end
OldErrGroup->>OldErrGroup: Wait()
OldErrGroup-->>Client: combined result + error
Client->>NewPool: WriteExecute(chunks)
rect rgb(200, 220, 250)
Note over NewPool: Initialize pool with<br/>max goroutines
end
loop Per Chunk (no index capture)
NewPool->>Chunk: Go(task) → execute chunk
Chunk-->>NewPool: response (collected)
end
NewPool->>NewPool: Wait()
NewPool-->>Client: combined result + error
rect rgb(240, 200, 200)
Note over NewPool: Auth errors via errors.As<br/>instead of type assertion
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
config/clients/go/template/client/client.mustache (2)
1786-1814: Add defensive nil check before dereferencing response.The writePool implementation looks correct with proper context propagation and error handling. However, when aggregating responses at lines 1856-1857, there's a potential nil pointer dereference if
writeResponseis nil.While
WriteExecuteappears to always return a non-nil response even on error, adding a defensive nil check would make the code more robust against future changes.Consider adding a nil check in the aggregation loop:
for _, writeResponse := range writeResponses { + if writeResponse != nil { response.Writes = append(response.Writes, writeResponse.Writes...) + } }
1825-1862: Add defensive nil checks in response aggregation.The deletePool implementation correctly mirrors the writePool pattern. However, the response aggregation at lines 1856-1862 should include nil checks to prevent potential panics.
Apply this diff to add defensive nil checks:
for _, writeResponse := range writeResponses { + if writeResponse != nil { response.Writes = append(response.Writes, writeResponse.Writes...) + } } for _, deleteResponse := range deleteResponses { + if deleteResponse != nil { response.Deletes = append(response.Deletes, deleteResponse.Deletes...) + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
config/clients/go/template/client/client.mustache(5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
config/**/*.mustache
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Validate mustache syntax and variable references across all template files, including CHANGELOG.md.mustache
Files:
config/clients/go/template/client/client.mustache
config/**/*.{json,mustache}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Never hardcode API keys or credentials in configuration or template files
Files:
config/clients/go/template/client/client.mustache
🔇 Additional comments (2)
config/clients/go/template/client/client.mustache (2)
7-7: LGTM! Standard library import for error unwrapping.The
errorspackage is correctly imported for theerrors.As()calls used in authentication error handling below.
1803-1808: LGTM! Correct use of errors.As for authentication error detection.The switch from type assertion to
errors.As()properly handles wrapped errors from the conc pool. Authentication errors fail fast (line 1805), while other errors are captured in the response structure for per-tuple error tracking.
|
Hi @AltuisticIsopod, we'll assign someone to review your PR. Thanks. |
Replace errgroup with conc pool in WriteExecute method
Description
This PR only moved "Write" to use Conc
References
openfga/go-sdk#193
Review Checklist
mainSummary by CodeRabbit