Commit dea4edff authored by Nick Thomas's avatar Nick Thomas

Merge branch 'use-contexts' into 'master'

Use http.Request contexts for Gitaly calls

See merge request !179
parents fadf660e 2b93db7a
......@@ -44,7 +44,7 @@ func handleSendBlobWithGitaly(w http.ResponseWriter, r *http.Request, params *bl
helper.Fail500(w, r, fmt.Errorf("commit.GetBlob: %v", err))
}
if err := commitClient.SendBlob(w, &params.TreeEntryRequest); err != nil {
if err := commitClient.SendBlob(r.Context(), w, &params.TreeEntryRequest); err != nil {
helper.Fail500(w, r, fmt.Errorf("commit.GetBlob: %v", err))
}
}
......
package git
import (
"context"
"fmt"
"io"
"net/http"
......@@ -8,8 +9,6 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"golang.org/x/net/context"
)
func GetInfoRefsHandler(a *api.API) http.Handler {
......@@ -35,7 +34,7 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
if a.GitalyServer.Address == "" {
err = handleGetInfoRefsLocally(w, a, rpc)
} else {
err = handleGetInfoRefsWithGitaly(w, a, rpc)
err = handleGetInfoRefsWithGitaly(r.Context(), w, a, rpc)
}
if err != nil {
......@@ -64,14 +63,12 @@ func handleGetInfoRefsLocally(w http.ResponseWriter, a *api.Response, rpc string
return nil
}
func handleGetInfoRefsWithGitaly(w http.ResponseWriter, a *api.Response, rpc string) error {
func handleGetInfoRefsWithGitaly(ctx context.Context, w http.ResponseWriter, a *api.Response, rpc string) error {
smarthttp, err := gitaly.NewSmartHTTPClient(a.GitalyServer)
if err != nil {
return fmt.Errorf("GetInfoRefsHandler: %v", err)
}
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
infoRefsResponseReader, err := smarthttp.InfoRefsResponseReader(ctx, &a.Repository, rpc)
if err != nil {
return fmt.Errorf("GetInfoRefsHandler: %v", err)
......
package git
import (
"context"
"fmt"
"io"
"net/http"
......@@ -23,7 +24,7 @@ func handleReceivePack(w *GitHttpResponseWriter, r *http.Request, a *api.Respons
if a.GitalyServer.Address == "" {
err = handleReceivePackLocally(a, r, cr, cw, action)
} else {
err = handleReceivePackWithGitaly(a, cr, cw)
err = handleReceivePackWithGitaly(r.Context(), a, cr, cw)
}
return err
......@@ -45,13 +46,13 @@ func handleReceivePackLocally(a *api.Response, r *http.Request, stdin io.Reader,
return nil
}
func handleReceivePackWithGitaly(a *api.Response, clientRequest io.Reader, clientResponse io.Writer) error {
func handleReceivePackWithGitaly(ctx context.Context, a *api.Response, clientRequest io.Reader, clientResponse io.Writer) error {
smarthttp, err := gitaly.NewSmartHTTPClient(a.GitalyServer)
if err != nil {
return fmt.Errorf("smarthttp.ReceivePack: %v", err)
}
if err := smarthttp.ReceivePack(&a.Repository, a.GL_ID, a.GL_REPOSITORY, clientRequest, clientResponse); err != nil {
if err := smarthttp.ReceivePack(ctx, &a.Repository, a.GL_ID, a.GL_REPOSITORY, clientRequest, clientResponse); err != nil {
return fmt.Errorf("smarthttp.ReceivePack: %v", err)
}
......
package git
import (
"context"
"fmt"
"io"
"net/http"
......@@ -30,7 +31,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
if a.GitalyServer.Address == "" {
err = handleUploadPackLocally(a, r, buffer, w, action)
} else {
err = handleUploadPackWithGitaly(a, buffer, w)
err = handleUploadPackWithGitaly(r.Context(), a, buffer, w)
}
return err
......@@ -57,13 +58,13 @@ func handleUploadPackLocally(a *api.Response, r *http.Request, stdin *os.File, s
return nil
}
func handleUploadPackWithGitaly(a *api.Response, clientRequest io.Reader, clientResponse io.Writer) error {
func handleUploadPackWithGitaly(ctx context.Context, a *api.Response, clientRequest io.Reader, clientResponse io.Writer) error {
smarthttp, err := gitaly.NewSmartHTTPClient(a.GitalyServer)
if err != nil {
return fmt.Errorf("smarthttp.UploadPack: %v", err)
}
if err := smarthttp.UploadPack(&a.Repository, clientRequest, clientResponse); err != nil {
if err := smarthttp.UploadPack(ctx, &a.Repository, clientRequest, clientResponse); err != nil {
return fmt.Errorf("smarthttp.UploadPack: %v", err)
}
......
package gitaly
import (
"context"
"fmt"
"io"
"net/http"
......@@ -8,18 +9,13 @@ import (
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/streamio"
"golang.org/x/net/context"
)
type CommitClient struct {
pb.CommitClient
}
func (client *CommitClient) SendBlob(w http.ResponseWriter, request *pb.TreeEntryRequest) error {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
func (client *CommitClient) SendBlob(ctx context.Context, w http.ResponseWriter, request *pb.TreeEntryRequest) error {
c, err := client.TreeEntry(ctx, request)
if err != nil {
return fmt.Errorf("rpc failed: %v", err)
......
package gitaly
import (
"context"
"fmt"
"io"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"gitlab.com/gitlab-org/gitaly/streamio"
"golang.org/x/net/context"
)
type SmartHTTPClient struct {
......@@ -40,10 +39,7 @@ func infoRefsReader(stream infoRefsClient) io.Reader {
})
}
func (client *SmartHTTPClient) ReceivePack(repo *pb.Repository, glId string, glRepository string, clientRequest io.Reader, clientResponse io.Writer) error {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Repository, glId string, glRepository string, clientRequest io.Reader, clientResponse io.Writer) error {
stream, err := client.PostReceivePack(ctx)
if err != nil {
return err
......@@ -89,10 +85,7 @@ func (client *SmartHTTPClient) ReceivePack(repo *pb.Repository, glId string, glR
return nil
}
func (client *SmartHTTPClient) UploadPack(repo *pb.Repository, clientRequest io.Reader, clientResponse io.Writer) error {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
func (client *SmartHTTPClient) UploadPack(ctx context.Context, repo *pb.Repository, clientRequest io.Reader, clientResponse io.Writer) error {
stream, err := client.PostUploadPack(ctx)
if err != nil {
return err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment