Skip to content
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
ggilmore merged 2 commits into
mainfrom
gprc-fix-p4-exec
Aug 30, 2023
Merged

grpc: p4exec: adjust client implementation to error immediately if a permission related error occurs#56298
ggilmore merged 2 commits into
mainfrom
gprc-fix-p4-exec

Conversation

@ggilmore

@ggilmore ggilmore commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

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

@cla-bot cla-bot Bot added the cla-signed label Aug 30, 2023
…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.
@ggilmore ggilmore marked this pull request as ready for review August 30, 2023 22:29
@sourcegraph-bot

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 0436cb8...d2929e8.

Notify File(s)
@eseliger cmd/gitserver/server/server_grpc.go
cmd/gitserver/server/server_test.go
internal/gitserver/client.go
internal/gitserver/client_test.go

@github-actions

Copy link
Copy Markdown
Contributor

The backport to 5.1 failed:

Validation Failed: "Could not resolve to a node with the global id of 'T_kwDOADy5QM4AWdx9'."

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.1

Then, create a pull request where the base branch is 5.1 and the compare/head branch is backport-56298-to-5.1.
See https://github.com/sourcegraph/sourcegraph/actions/runs/6030911948/jobs/14760 for more information.
Make sure to tag @sourcegraph/release-guild in the pull request description.
Once the backport pull request is created, kindly remove the release-blocker from this pull request.

@github-actions github-actions Bot added backports failed-backport-to-5.1 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases labels Aug 30, 2023
github-actions Bot pushed a commit that referenced this pull request Aug 30, 2023
…permission related error occurs (#56298)

(cherry picked from commit f7a1545)
keegancsmith pushed a commit that referenced this pull request Aug 31, 2023
…mediately if a permission related error occurs (#56301)

grpc: p4exec: adjust client implementation to error immediately if a permission related error occurs (#56298)

(cherry picked from commit f7a1545)

Co-authored-by: Geoffrey Gilmore <geoffrey@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backports cla-signed release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants