This repository was archived by the owner on Sep 30, 2024. It is now read-only.
grpc: p4exec: adjust client implementation to error immediately if a permission related error occurs#56298
Merged
Conversation
…permission related error occurs
…on-zero exit code The panic is only caused by the unrealistic test scenario in the mock. Looking at the real implementation, there is no scenario where we'd return a non-zero exit code _and_ no error from the command itself.
Contributor
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 0436cb8...d2929e8.
|
eseliger
approved these changes
Aug 30, 2023
Contributor
|
The backport to To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.1 5.1
# Navigate to the new working tree
cd .worktrees/backport-5.1
# Create a new branch
git switch --create backport-56298-to-5.1
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 f7a1545fb12a6bd1b3b7ce221b8e0c45ec14418d
# Push it to GitHub
git push --set-upstream origin backport-56298-to-5.1
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.1Then, create a pull request where the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
background
Our REST P4Exec implementation first checks to see if the provided credentials are valid before running streaming the p4 output. If it's invalid, the server returns a http.BadRequest response to the client:
https://github.com/sourcegraph/sourcegraph/blob/3e50ff1a904b8fb0e6d2eb010e33cab56503c91d/cmd/gitserver/server/server.go#L1731-L1739
Our client implementation is written in such a way where these errors are immediately returned to the caller, without the need to consume the response body:
https://github.com/sourcegraph/sourcegraph/blob/457dc4813fc7614d84f91d0fb40404068ff1e362/internal/gitserver/client.go#L944-L956
old gRPC behavior
The gRPC version of this function does the same credentials check, but it didn't maintain the invariant of immediately
returning credential errors to the caller. Instead, the caller is required to start consuming the streamed response in order to see the error:
https://github.com/sourcegraph/sourcegraph/blob/3e50ff1a904b8fb0e6d2eb010e33cab56503c91d/internal/gitserver/client.go#L890-L912
This broke a call-site that only checked the immediate error returned by the client, and didn't actually consume the reader:
https://github.com/sourcegraph/sourcegraph/blob/dc0dfd1178326797e8c72f66af0c258960c3178c/internal/batches/sources/perforce.go#L82-L95
new gRPC behavior
This PR adjust the gRPC client to cache the first message it receives from the stream. If the first message is a permissions / credentials related error - it returns immediately before returning the stream. Otherwise, it returns the stream and yields all the same messages as it did before.
Test plan
Unit tests