summaryrefslogtreecommitdiff
path: root/workhorse/internal
diff options
context:
space:
mode:
Diffstat (limited to 'workhorse/internal')
-rw-r--r--workhorse/internal/api/api.go8
-rw-r--r--workhorse/internal/config/config.go20
-rw-r--r--workhorse/internal/git/archive.go2
-rw-r--r--workhorse/internal/git/archive_test.go2
-rw-r--r--workhorse/internal/git/blob.go2
-rw-r--r--workhorse/internal/git/diff.go2
-rw-r--r--workhorse/internal/git/format-patch.go2
-rw-r--r--workhorse/internal/git/snapshot.go2
-rw-r--r--workhorse/internal/git/upload-pack_test.go2
-rw-r--r--workhorse/internal/gitaly/blob.go4
-rw-r--r--workhorse/internal/gitaly/diff.go4
-rw-r--r--workhorse/internal/gitaly/gitaly.go6
-rw-r--r--workhorse/internal/gitaly/namespace.go2
-rw-r--r--workhorse/internal/gitaly/repository.go4
-rw-r--r--workhorse/internal/gitaly/smarthttp.go4
-rw-r--r--workhorse/internal/gitaly/unmarshal_test.go2
-rw-r--r--workhorse/internal/httprs/httprs_test.go8
-rw-r--r--workhorse/internal/lsif_transformer/parser/code_hover.go20
-rw-r--r--workhorse/internal/lsif_transformer/parser/code_hover_test.go24
-rw-r--r--workhorse/internal/lsif_transformer/parser/hovers.go13
-rw-r--r--workhorse/internal/objectstore/multipart.go11
-rw-r--r--workhorse/internal/redis/keywatcher.go18
-rw-r--r--workhorse/internal/redis/keywatcher_test.go55
-rw-r--r--workhorse/internal/redis/redis.go64
-rw-r--r--workhorse/internal/redis/redis_test.go16
-rw-r--r--workhorse/internal/testhelper/gitaly.go2
26 files changed, 190 insertions, 109 deletions
diff --git a/workhorse/internal/api/api.go b/workhorse/internal/api/api.go
index d8e2a7b0d9f..5dae6eb01bb 100644
--- a/workhorse/internal/api/api.go
+++ b/workhorse/internal/api/api.go
@@ -14,7 +14,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/config"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
@@ -308,7 +308,7 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
return
}
- httpResponse.Body.Close() // Free up the Unicorn worker
+ httpResponse.Body.Close() // Free up the Puma thread
copyAuthHeader(httpResponse, w)
@@ -347,7 +347,7 @@ func copyAuthHeader(httpResponse *http.Response, w http.ResponseWriter) {
func passResponseBack(httpResponse *http.Response, w http.ResponseWriter, r *http.Request) {
// NGINX response buffering is disabled on this path (with
- // X-Accel-Buffering: no) but we still want to free up the Unicorn worker
+ // X-Accel-Buffering: no) but we still want to free up the Puma thread
// that generated httpResponse as fast as possible. To do this we buffer
// the entire response body in memory before sending it on.
responseBody, err := bufferResponse(httpResponse.Body)
@@ -355,7 +355,7 @@ func passResponseBack(httpResponse *http.Response, w http.ResponseWriter, r *htt
helper.Fail500(w, r, err)
return
}
- httpResponse.Body.Close() // Free up the Unicorn worker
+ httpResponse.Body.Close() // Free up the Puma thread
bytesTotal.Add(float64(responseBody.Len()))
for k, v := range httpResponse.Header {
diff --git a/workhorse/internal/config/config.go b/workhorse/internal/config/config.go
index 84849c72744..9f214385f81 100644
--- a/workhorse/internal/config/config.go
+++ b/workhorse/internal/config/config.go
@@ -28,7 +28,7 @@ type TomlDuration struct {
time.Duration
}
-func (d *TomlDuration) UnmarshalTest(text []byte) error {
+func (d *TomlDuration) UnmarshalText(text []byte) error {
temp, err := time.ParseDuration(string(text))
d.Duration = temp
return err
@@ -70,16 +70,13 @@ type AzureCredentials struct {
}
type RedisConfig struct {
- URL TomlURL
- Sentinel []TomlURL
- SentinelMaster string
- Password string
- DB *int
- ReadTimeout *TomlDuration
- WriteTimeout *TomlDuration
- KeepAlivePeriod *TomlDuration
- MaxIdle *int
- MaxActive *int
+ URL TomlURL
+ Sentinel []TomlURL
+ SentinelMaster string
+ Password string
+ DB *int
+ MaxIdle *int
+ MaxActive *int
}
type ImageResizerConfig struct {
@@ -106,6 +103,7 @@ type Config struct {
PropagateCorrelationID bool `toml:"-"`
ImageResizerConfig ImageResizerConfig `toml:"image_resizer"`
AltDocumentRoot string `toml:"alt_document_root"`
+ ShutdownTimeout TomlDuration `toml:"shutdown_timeout"`
}
var DefaultImageResizerConfig = ImageResizerConfig{
diff --git a/workhorse/internal/git/archive.go b/workhorse/internal/git/archive.go
index 361e1d00c0b..856076010e8 100644
--- a/workhorse/internal/git/archive.go
+++ b/workhorse/internal/git/archive.go
@@ -20,7 +20,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
diff --git a/workhorse/internal/git/archive_test.go b/workhorse/internal/git/archive_test.go
index 4b0753499e5..2981121dfd6 100644
--- a/workhorse/internal/git/archive_test.go
+++ b/workhorse/internal/git/archive_test.go
@@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
diff --git a/workhorse/internal/git/blob.go b/workhorse/internal/git/blob.go
index 472f5d0bc96..68d342862fd 100644
--- a/workhorse/internal/git/blob.go
+++ b/workhorse/internal/git/blob.go
@@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
diff --git a/workhorse/internal/git/diff.go b/workhorse/internal/git/diff.go
index 51cadeecb65..49d979d0df4 100644
--- a/workhorse/internal/git/diff.go
+++ b/workhorse/internal/git/diff.go
@@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
diff --git a/workhorse/internal/git/format-patch.go b/workhorse/internal/git/format-patch.go
index 3a65fc2a7a2..62519e5cc2f 100644
--- a/workhorse/internal/git/format-patch.go
+++ b/workhorse/internal/git/format-patch.go
@@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
diff --git a/workhorse/internal/git/snapshot.go b/workhorse/internal/git/snapshot.go
index bd9405a28d0..553af7f4c38 100644
--- a/workhorse/internal/git/snapshot.go
+++ b/workhorse/internal/git/snapshot.go
@@ -5,7 +5,7 @@ import (
"io"
"net/http"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
diff --git a/workhorse/internal/git/upload-pack_test.go b/workhorse/internal/git/upload-pack_test.go
index c198939d5df..9ee199a5402 100644
--- a/workhorse/internal/git/upload-pack_test.go
+++ b/workhorse/internal/git/upload-pack_test.go
@@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
diff --git a/workhorse/internal/gitaly/blob.go b/workhorse/internal/gitaly/blob.go
index c6f5d6676f3..123fa6e9a4c 100644
--- a/workhorse/internal/gitaly/blob.go
+++ b/workhorse/internal/gitaly/blob.go
@@ -7,8 +7,8 @@ import (
"net/http"
"strconv"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/streamio"
)
type BlobClient struct {
diff --git a/workhorse/internal/gitaly/diff.go b/workhorse/internal/gitaly/diff.go
index 035a58ec6fd..50bf848b8d3 100644
--- a/workhorse/internal/gitaly/diff.go
+++ b/workhorse/internal/gitaly/diff.go
@@ -6,8 +6,8 @@ import (
"io"
"net/http"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/streamio"
)
type DiffClient struct {
diff --git a/workhorse/internal/gitaly/gitaly.go b/workhorse/internal/gitaly/gitaly.go
index c739ac8d9b2..0aa35325555 100644
--- a/workhorse/internal/gitaly/gitaly.go
+++ b/workhorse/internal/gitaly/gitaly.go
@@ -11,9 +11,9 @@ import (
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
- gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
- gitalyclient "gitlab.com/gitlab-org/gitaly/client"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ gitalyauth "gitlab.com/gitlab-org/gitaly/v14/auth"
+ gitalyclient "gitlab.com/gitlab-org/gitaly/v14/client"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
diff --git a/workhorse/internal/gitaly/namespace.go b/workhorse/internal/gitaly/namespace.go
index 6db6ed4fc32..e2fe7a3c63f 100644
--- a/workhorse/internal/gitaly/namespace.go
+++ b/workhorse/internal/gitaly/namespace.go
@@ -1,6 +1,6 @@
package gitaly
-import "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+import "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
// NamespaceClient encapsulates NamespaceService calls
type NamespaceClient struct {
diff --git a/workhorse/internal/gitaly/repository.go b/workhorse/internal/gitaly/repository.go
index e3ec3257a85..425a28befe8 100644
--- a/workhorse/internal/gitaly/repository.go
+++ b/workhorse/internal/gitaly/repository.go
@@ -5,8 +5,8 @@ import (
"fmt"
"io"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/streamio"
)
// RepositoryClient encapsulates RepositoryService calls
diff --git a/workhorse/internal/gitaly/smarthttp.go b/workhorse/internal/gitaly/smarthttp.go
index d1fe6fae5ba..69656ab0a92 100644
--- a/workhorse/internal/gitaly/smarthttp.go
+++ b/workhorse/internal/gitaly/smarthttp.go
@@ -5,8 +5,8 @@ import (
"fmt"
"io"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
- "gitlab.com/gitlab-org/gitaly/streamio"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/streamio"
)
type SmartHTTPClient struct {
diff --git a/workhorse/internal/gitaly/unmarshal_test.go b/workhorse/internal/gitaly/unmarshal_test.go
index e2256903339..270b96f900d 100644
--- a/workhorse/internal/gitaly/unmarshal_test.go
+++ b/workhorse/internal/gitaly/unmarshal_test.go
@@ -4,7 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
func TestUnmarshalJSON(t *testing.T) {
diff --git a/workhorse/internal/httprs/httprs_test.go b/workhorse/internal/httprs/httprs_test.go
index 62279d895c9..e26d2d21215 100644
--- a/workhorse/internal/httprs/httprs_test.go
+++ b/workhorse/internal/httprs/httprs_test.go
@@ -53,6 +53,10 @@ func (f *fakeRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
if err != nil {
return nil, err
}
+ if err := os.Remove(fw.tmp.Name()); err != nil {
+ return nil, err
+ }
+
if f.downgradeZeroToNoRange {
// There are implementations that downgrades bytes=0- to a normal un-ranged GET
if r.Header.Get("Range") == "bytes=0-" {
@@ -79,6 +83,10 @@ func newRSFactory(flags int) RSFactory {
if err != nil {
return nil
}
+ if err := os.Remove(tmp.Name()); err != nil {
+ return nil
+ }
+
for i := 0; i < SZ; i++ {
tmp.WriteString(fmt.Sprintf("%04d", i))
}
diff --git a/workhorse/internal/lsif_transformer/parser/code_hover.go b/workhorse/internal/lsif_transformer/parser/code_hover.go
index dbdaba643d1..5651ea8e5a3 100644
--- a/workhorse/internal/lsif_transformer/parser/code_hover.go
+++ b/workhorse/internal/lsif_transformer/parser/code_hover.go
@@ -50,9 +50,29 @@ func (ts *truncatableString) MarshalJSON() ([]byte, error) {
return json.Marshal(ts.Value)
}
+func newCodeHovers(contents json.RawMessage) ([]*codeHover, error) {
+ var rawContents []json.RawMessage
+ if err := json.Unmarshal(contents, &rawContents); err != nil {
+ rawContents = []json.RawMessage{contents}
+ }
+
+ codeHovers := []*codeHover{}
+ for _, rawContent := range rawContents {
+ c, err := newCodeHover(rawContent)
+ if err != nil {
+ return nil, err
+ }
+
+ codeHovers = append(codeHovers, c)
+ }
+
+ return codeHovers, nil
+}
+
func newCodeHover(content json.RawMessage) (*codeHover, error) {
// Hover value can be either an object: { "value": "func main()", "language": "go" }
// Or a string with documentation
+ // Or a markdown object: { "value": "```go\nfunc main()\n```", "kind": "markdown" }
// We try to unmarshal the content into a string and if we fail, we unmarshal it into an object
var c codeHover
if err := json.Unmarshal(content, &c.TruncatedValue); err != nil {
diff --git a/workhorse/internal/lsif_transformer/parser/code_hover_test.go b/workhorse/internal/lsif_transformer/parser/code_hover_test.go
index 2030e530155..c09636b2f76 100644
--- a/workhorse/internal/lsif_transformer/parser/code_hover_test.go
+++ b/workhorse/internal/lsif_transformer/parser/code_hover_test.go
@@ -64,21 +64,33 @@ func TestHighlight(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- raw := []byte(fmt.Sprintf(`{"language":"%s","value":"%s"}`, tt.language, tt.value))
- c, err := newCodeHover(json.RawMessage(raw))
+ raw := []byte(fmt.Sprintf(`[{"language":"%s","value":"%s"}]`, tt.language, tt.value))
+ c, err := newCodeHovers(json.RawMessage(raw))
require.NoError(t, err)
- require.Equal(t, tt.want, c.Tokens)
+ require.Len(t, c, 1)
+ require.Equal(t, tt.want, c[0].Tokens)
})
}
}
func TestMarkdown(t *testing.T) {
- value := `"This method reverses a string \n\n"`
- c, err := newCodeHover(json.RawMessage(value))
+ value := `["This method reverses a string \n\n"]`
+ c, err := newCodeHovers(json.RawMessage(value))
require.NoError(t, err)
- require.Equal(t, "This method reverses a string \n\n", c.TruncatedValue.Value)
+ require.Len(t, c, 1)
+ require.Equal(t, "This method reverses a string \n\n", c[0].TruncatedValue.Value)
+}
+
+func TestMarkdownContentsFormat(t *testing.T) {
+ value := `{"kind":"markdown","value":"some _markdown_ **text**"}`
+ c, err := newCodeHovers(json.RawMessage(value))
+
+ require.NoError(t, err)
+ require.Len(t, c, 1)
+ require.Equal(t, [][]token(nil), c[0].Tokens)
+ require.Equal(t, "some _markdown_ **text**", c[0].TruncatedValue.Value)
}
func TestTruncatedValue(t *testing.T) {
diff --git a/workhorse/internal/lsif_transformer/parser/hovers.go b/workhorse/internal/lsif_transformer/parser/hovers.go
index e96d7e4fca3..5889d595ade 100644
--- a/workhorse/internal/lsif_transformer/parser/hovers.go
+++ b/workhorse/internal/lsif_transformer/parser/hovers.go
@@ -18,7 +18,7 @@ type Hovers struct {
}
type RawResult struct {
- Contents []json.RawMessage `json:"contents"`
+ Contents json.RawMessage `json:"contents"`
}
type RawData struct {
@@ -107,14 +107,9 @@ func (h *Hovers) addData(line []byte) error {
return err
}
- codeHovers := []*codeHover{}
- for _, rawContent := range rawData.Result.Contents {
- c, err := newCodeHover(rawContent)
- if err != nil {
- return err
- }
-
- codeHovers = append(codeHovers, c)
+ codeHovers, err := newCodeHovers(rawData.Result.Contents)
+ if err != nil {
+ return err
}
codeHoversData, err := json.Marshal(codeHovers)
diff --git a/workhorse/internal/objectstore/multipart.go b/workhorse/internal/objectstore/multipart.go
index fd1c0ed487d..4c5b64b27ee 100644
--- a/workhorse/internal/objectstore/multipart.go
+++ b/workhorse/internal/objectstore/multipart.go
@@ -11,7 +11,6 @@ import (
"net/http"
"os"
- "gitlab.com/gitlab-org/labkit/log"
"gitlab.com/gitlab-org/labkit/mask"
)
@@ -98,11 +97,11 @@ func (m *Multipart) readAndUploadOnePart(ctx context.Context, partURL string, pu
if err != nil {
return nil, fmt.Errorf("create temporary buffer file: %v", err)
}
- defer func(path string) {
- if err := os.Remove(path); err != nil {
- log.WithError(err).WithField("file", path).Warning("Unable to delete temporary file")
- }
- }(file.Name())
+ defer file.Close()
+
+ if err := os.Remove(file.Name()); err != nil {
+ return nil, err
+ }
n, err := io.Copy(file, src)
if err != nil {
diff --git a/workhorse/internal/redis/keywatcher.go b/workhorse/internal/redis/keywatcher.go
index 8f3e61b5e9f..10d80d13d22 100644
--- a/workhorse/internal/redis/keywatcher.go
+++ b/workhorse/internal/redis/keywatcher.go
@@ -17,6 +17,7 @@ import (
var (
keyWatcher = make(map[string][]chan string)
keyWatcherMutex sync.Mutex
+ shutdown = make(chan struct{})
redisReconnectTimeout = backoff.Backoff{
//These are the defaults
Min: 100 * time.Millisecond,
@@ -112,6 +113,20 @@ func Process() {
}
}
+func Shutdown() {
+ log.Info("keywatcher: shutting down")
+
+ keyWatcherMutex.Lock()
+ defer keyWatcherMutex.Unlock()
+
+ select {
+ case <-shutdown:
+ // already closed
+ default:
+ close(shutdown)
+ }
+}
+
func notifyChanWatchers(key, value string) {
keyWatcherMutex.Lock()
defer keyWatcherMutex.Unlock()
@@ -182,6 +197,9 @@ func WatchKey(key, value string, timeout time.Duration) (WatchKeyStatus, error)
}
select {
+ case <-shutdown:
+ log.WithFields(log.Fields{"key": key}).Info("stopping watch due to shutdown")
+ return WatchKeyStatusNoChange, nil
case currentValue := <-kw.Chan:
if currentValue == "" {
return WatchKeyStatusNoChange, fmt.Errorf("keywatcher: redis GET failed")
diff --git a/workhorse/internal/redis/keywatcher_test.go b/workhorse/internal/redis/keywatcher_test.go
index f1ee77e2194..99892bc64b8 100644
--- a/workhorse/internal/redis/keywatcher_test.go
+++ b/workhorse/internal/redis/keywatcher_test.go
@@ -160,3 +160,58 @@ func TestWatchKeyMassivelyParallel(t *testing.T) {
processMessages(runTimes, "somethingelse")
wg.Wait()
}
+
+func TestShutdown(t *testing.T) {
+ conn, td := setupMockPool()
+ defer td()
+ defer func() { shutdown = make(chan struct{}) }()
+
+ conn.Command("GET", runnerKey).Expect("something")
+
+ wg := &sync.WaitGroup{}
+ wg.Add(2)
+
+ go func() {
+ val, err := WatchKey(runnerKey, "something", 10*time.Second)
+
+ require.NoError(t, err, "Expected no error")
+ require.Equal(t, WatchKeyStatusNoChange, val, "Expected value not to change")
+ wg.Done()
+ }()
+
+ go func() {
+ for countWatchers(runnerKey) == 0 {
+ time.Sleep(time.Millisecond)
+ }
+
+ require.Equal(t, 1, countWatchers(runnerKey))
+
+ Shutdown()
+ wg.Done()
+ }()
+
+ wg.Wait()
+
+ for countWatchers(runnerKey) == 1 {
+ time.Sleep(time.Millisecond)
+ }
+
+ require.Equal(t, 0, countWatchers(runnerKey))
+
+ // Adding a key after the shutdown should result in an immediate response
+ var val WatchKeyStatus
+ var err error
+ done := make(chan struct{})
+ go func() {
+ val, err = WatchKey(runnerKey, "something", 10*time.Second)
+ close(done)
+ }()
+
+ select {
+ case <-done:
+ require.NoError(t, err, "Expected no error")
+ require.Equal(t, WatchKeyStatusNoChange, val, "Expected value not to change")
+ case <-time.After(100 * time.Millisecond):
+ t.Fatal("timeout waiting for WatchKey")
+ }
+}
diff --git a/workhorse/internal/redis/redis.go b/workhorse/internal/redis/redis.go
index 0029a2a9e2b..b11a8184bca 100644
--- a/workhorse/internal/redis/redis.go
+++ b/workhorse/internal/redis/redis.go
@@ -113,21 +113,9 @@ var poolDialFunc func() (redis.Conn, error)
var workerDialFunc func() (redis.Conn, error)
func timeoutDialOptions(cfg *config.RedisConfig) []redis.DialOption {
- readTimeout := defaultReadTimeout
- writeTimeout := defaultWriteTimeout
-
- if cfg != nil {
- if cfg.ReadTimeout != nil {
- readTimeout = cfg.ReadTimeout.Duration
- }
-
- if cfg.WriteTimeout != nil {
- writeTimeout = cfg.WriteTimeout.Duration
- }
- }
return []redis.DialOption{
- redis.DialReadTimeout(readTimeout),
- redis.DialWriteTimeout(writeTimeout),
+ redis.DialReadTimeout(defaultReadTimeout),
+ redis.DialWriteTimeout(defaultWriteTimeout),
}
}
@@ -148,47 +136,45 @@ func dialOptionsBuilder(cfg *config.RedisConfig, setTimeouts bool) []redis.DialO
return dopts
}
-func keepAliveDialer(timeout time.Duration) func(string, string) (net.Conn, error) {
- return func(network, address string) (net.Conn, error) {
- addr, err := net.ResolveTCPAddr(network, address)
- if err != nil {
- return nil, err
- }
- tc, err := net.DialTCP(network, nil, addr)
- if err != nil {
- return nil, err
- }
- if err := tc.SetKeepAlive(true); err != nil {
- return nil, err
- }
- if err := tc.SetKeepAlivePeriod(timeout); err != nil {
- return nil, err
- }
- return tc, nil
+func keepAliveDialer(network, address string) (net.Conn, error) {
+ addr, err := net.ResolveTCPAddr(network, address)
+ if err != nil {
+ return nil, err
}
+ tc, err := net.DialTCP(network, nil, addr)
+ if err != nil {
+ return nil, err
+ }
+ if err := tc.SetKeepAlive(true); err != nil {
+ return nil, err
+ }
+ if err := tc.SetKeepAlivePeriod(defaultKeepAlivePeriod); err != nil {
+ return nil, err
+ }
+ return tc, nil
}
type redisDialerFunc func() (redis.Conn, error)
-func sentinelDialer(dopts []redis.DialOption, keepAlivePeriod time.Duration) redisDialerFunc {
+func sentinelDialer(dopts []redis.DialOption) redisDialerFunc {
return func() (redis.Conn, error) {
address, err := sntnl.MasterAddr()
if err != nil {
errorCounter.WithLabelValues("master", "sentinel").Inc()
return nil, err
}
- dopts = append(dopts, redis.DialNetDial(keepAliveDialer(keepAlivePeriod)))
+ dopts = append(dopts, redis.DialNetDial(keepAliveDialer))
return redisDial("tcp", address, dopts...)
}
}
-func defaultDialer(dopts []redis.DialOption, keepAlivePeriod time.Duration, url url.URL) redisDialerFunc {
+func defaultDialer(dopts []redis.DialOption, url url.URL) redisDialerFunc {
return func() (redis.Conn, error) {
if url.Scheme == "unix" {
return redisDial(url.Scheme, url.Path, dopts...)
}
- dopts = append(dopts, redis.DialNetDial(keepAliveDialer(keepAlivePeriod)))
+ dopts = append(dopts, redis.DialNetDial(keepAliveDialer))
// redis.DialURL only works with redis[s]:// URLs
if url.Scheme == "redis" || url.Scheme == "rediss" {
@@ -231,15 +217,11 @@ func countDialer(dialer redisDialerFunc) redisDialerFunc {
// DefaultDialFunc should always used. Only exception is for unit-tests.
func DefaultDialFunc(cfg *config.RedisConfig, setReadTimeout bool) func() (redis.Conn, error) {
- keepAlivePeriod := defaultKeepAlivePeriod
- if cfg.KeepAlivePeriod != nil {
- keepAlivePeriod = cfg.KeepAlivePeriod.Duration
- }
dopts := dialOptionsBuilder(cfg, setReadTimeout)
if sntnl != nil {
- return countDialer(sentinelDialer(dopts, keepAlivePeriod))
+ return countDialer(sentinelDialer(dopts))
}
- return countDialer(defaultDialer(dopts, keepAlivePeriod, cfg.URL.URL))
+ return countDialer(defaultDialer(dopts, cfg.URL.URL))
}
// Configure redis-connection
diff --git a/workhorse/internal/redis/redis_test.go b/workhorse/internal/redis/redis_test.go
index f4b4120517d..eee2f99bbbf 100644
--- a/workhorse/internal/redis/redis_test.go
+++ b/workhorse/internal/redis/redis_test.go
@@ -96,13 +96,11 @@ func TestConfigureMinimalConfig(t *testing.T) {
func TestConfigureFullConfig(t *testing.T) {
i, a := 4, 10
- r := config.TomlDuration{Duration: 3}
cfg := &config.RedisConfig{
- URL: config.TomlURL{},
- Password: "",
- MaxIdle: &i,
- MaxActive: &a,
- ReadTimeout: &r,
+ URL: config.TomlURL{},
+ Password: "",
+ MaxIdle: &i,
+ MaxActive: &a,
}
Configure(cfg, DefaultDialFunc)
@@ -219,11 +217,7 @@ func TestDialOptionsBuildersSetTimeouts(t *testing.T) {
}
func TestDialOptionsBuildersSetTimeoutsConfig(t *testing.T) {
- cfg := &config.RedisConfig{
- ReadTimeout: &config.TomlDuration{Duration: time.Second * time.Duration(15)},
- WriteTimeout: &config.TomlDuration{Duration: time.Second * time.Duration(15)},
- }
- dopts := dialOptionsBuilder(cfg, true)
+ dopts := dialOptionsBuilder(nil, true)
require.Equal(t, 2, len(dopts))
}
diff --git a/workhorse/internal/testhelper/gitaly.go b/workhorse/internal/testhelper/gitaly.go
index 24884505440..020a5863e2d 100644
--- a/workhorse/internal/testhelper/gitaly.go
+++ b/workhorse/internal/testhelper/gitaly.go
@@ -10,7 +10,7 @@ import (
"github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/274
"github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab-workhorse/-/issues/274
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"gitlab.com/gitlab-org/labkit/log"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"