As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit dddd5c2e authored by Patrick Bajao's avatar Patrick Bajao
Browse files

Merge branch '518-fix-thread-safety' into 'main'

Fix thread-safety issues in gitlab-shell

Closes #518

See merge request gitlab-org/gitlab-shell!462
parents 88f94337 4af9308b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -6,6 +6,7 @@ import (
"net/url"
"path"
"path/filepath"
"sync"
"gitlab.com/gitlab-org/gitlab-shell/client"
yaml "gopkg.in/yaml.v2"
Loading
Loading
@@ -46,21 +47,23 @@ type Config struct {
SslCertDir string `yaml:"ssl_cert_dir"`
HttpSettings HttpSettingsConfig `yaml:"http_settings"`
Server ServerConfig `yaml:"sshd"`
HttpClient *client.HttpClient `-`
httpClient *client.HttpClient
httpClientOnce sync.Once
}
// The defaults to apply before parsing the config file(s).
var (
DefaultConfig = Config{
LogFile: "gitlab-shell.log",
LogFile: "gitlab-shell.log",
LogFormat: "text",
Server: DefaultServerConfig,
User: "git",
Server: DefaultServerConfig,
User: "git",
}
DefaultServerConfig = ServerConfig{
Listen: "[::]:22",
WebListen: "localhost:9122",
Listen: "[::]:22",
WebListen: "localhost:9122",
ConcurrentSessionsLimit: 10,
HostKeyFiles: []string{
"/run/secrets/ssh-hostkeys/ssh_host_rsa_key",
Loading
Loading
@@ -70,22 +73,19 @@ var (
}
)
func (c *Config) GetHttpClient() *client.HttpClient {
if c.HttpClient != nil {
return c.HttpClient
}
client := client.NewHTTPClient(
c.GitlabUrl,
c.GitlabRelativeURLRoot,
c.HttpSettings.CaFile,
c.HttpSettings.CaPath,
c.HttpSettings.SelfSignedCert,
c.HttpSettings.ReadTimeoutSeconds)
c.HttpClient = client
return client
func (c *Config) HttpClient() *client.HttpClient {
c.httpClientOnce.Do(func() {
c.httpClient = client.NewHTTPClient(
c.GitlabUrl,
c.GitlabRelativeURLRoot,
c.HttpSettings.CaFile,
c.HttpSettings.CaPath,
c.HttpSettings.SelfSignedCert,
c.HttpSettings.ReadTimeoutSeconds,
)
})
return c.httpClient
}
// NewFromDirExternal returns a new config from a given root dir. It also applies defaults appropriate for
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ var (
)
func GetClient(config *config.Config) (*client.GitlabNetClient, error) {
httpClient := config.GetHttpClient()
httpClient := config.HttpClient()
if httpClient == nil {
return nil, fmt.Errorf("Unsupported protocol")
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment