Skip to content

Commit

Permalink
virtcontainers: clh: Do not use the default HTTP client
Browse files Browse the repository at this point in the history
When enabling tracing with Cloud Hypervisor, we end up establishing 2
connections to 2 different HTTP servers: The Cloud Hypervisor API one
that runs over a UNIX socket and the Jaeger endpoint running over UDP.

Both connections use the default HTTP golang client instance, and thus
share the same transport layer. As the Cloud Hypervisor implementation
sets it up to be over a Unix socket, the jaeger uploader ends up going
through that transport as well, and sending its spans to the Cloud
Hypervisor API server.

We fix that by giving the Cloud Hypervisor implementation its own HTTP
client instance and we avoid sharing it with anything else in the shim.

Fixes #2364

Signed-off-by: Samuel Ortiz <samuel.e.ortiz@protonmail.com>
  • Loading branch information
sameo committed Jul 30, 2021
1 parent 0c91304 commit 760ec4e
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/runtime/virtcontainers/clh.go
Expand Up @@ -281,6 +281,22 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ
}
clh.state.apiSocket = apiSocketPath

cfg := chclient.NewConfiguration()
cfg.HTTPClient = &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, path string) (net.Conn, error) {
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
if err != nil {
return nil, err
}

return net.DialUnix("unix", nil, addr)
},
},
}

clh.APIClient = chclient.NewAPIClient(cfg).DefaultApi

clh.virtiofsd = &virtiofsd{
path: clh.config.VirtioFSDaemon,
sourcePath: filepath.Join(getSharePath(clh.id)),
Expand Down Expand Up @@ -968,34 +984,9 @@ func (clh *cloudHypervisor) isClhRunning(timeout uint) (bool, error) {
}

func (clh *cloudHypervisor) client() clhClient {
if clh.APIClient == nil {
clh.APIClient = clh.newAPIClient()
}

return clh.APIClient
}

func (clh *cloudHypervisor) newAPIClient() *chclient.DefaultApiService {

cfg := chclient.NewConfiguration()

socketTransport := &http.Transport{
DialContext: func(ctx context.Context, network, path string) (net.Conn, error) {
addr, err := net.ResolveUnixAddr("unix", clh.state.apiSocket)
if err != nil {
return nil, err
}

return net.DialUnix("unix", nil, addr)
},
}

cfg.HTTPClient = http.DefaultClient
cfg.HTTPClient.Transport = socketTransport

return chclient.NewAPIClient(cfg).DefaultApi
}

func openAPIClientError(err error) error {

if err == nil {
Expand Down

0 comments on commit 760ec4e

Please sign in to comment.